Jump to content


Photo

Eeprom Routines


2 replies to this topic

#1 mityeltu

mityeltu

    Regular

  • EstablishedMember
  • Pip
  • 79 posts
  • Gender:Male
  • Location:Tennessee
  • Interests:Communications

Posted 27 April 2010 - 05:50 PM

Has anyone had any issues with the SB Builtin EEPROM routines?

I hope sombody can enlighten me on this. I am working on a project for my boss and I'm running out of time. I have been trying unsuccesffully to write to my eeprom. The read routine works fine, but not the write. I am using the PIC16f887 with 8MHz internal oscillator. My oversimplified code is as follows:

#include <system.h>
#include <eeprom.h>
#include <lcd_driver.h>

#define LCD_ARGS  2, /* Interface type&#58; mode 0 = 8bit, 1 = 4bit&#40;low nibble&#41;, 2 = 4bit&#40;upper nibble&#41; */ \
	1,	 /* Use busy signal&#58; 1 = use busy, 0 = use time delays */\
	PORTB, TRISB,  /* Data port and data port tris register */ \
	PORTB, TRISB,  /* Control port and control port tris register */ \
	1,	/* Bit number of control port is connected to RS */ \
	2,	/* Bit number of control port is connected to RW */ \
	3	 /* Bit number of control port is connected to Enable */
	
unsigned char one, adr, dat;
void mcu_setup&#40;void&#41;;

void main&#40;&#41;
{
mcu_setup&#40;&#41;;

//writing does not work
adr = 0x10;
dat = 0x01;
eeprom_write&#40;adr,dat&#41;;

adr = 0x00;
one = eeprom_read&#40;adr&#41;;
lprintf&#40;&#34;m&#58;&#34;&#41;;
one = one + 48;
lcd_write&#40;one&#41;;
while&#40;1&#41;
{}
}


void mcu_setup&#40;&#41;/**********************************MCU_SETUP***********************************/
{
	intcon = 0x00;
	adcon0 = 0;
	ansel = 0;
	anselh = 0;
	
	trisa = 0xff;//porta inputs
	trisb = 0x00;//portb outputs - lcd data
	set_bit&#40;trisb,0&#41;;//input for int0 -- not used
	trisc = 0x00;//portc output
	portc = 0;
	trisd = 0x00;//portd output
	portd = 0;
	trise = 0xff;//porte input
	
	lcd_setup&#40;&#41;;
}////////////////////////////////////////////////END MCU_SETUP////////////////////////////////////


#2 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 659 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 27 April 2010 - 07:25 PM

You are calling the read function just after you called the write function.

Writing to EEPROM takes time (several ms) so you have to wait for the write cycle to complete first. You can do this by waiting a fixed delay (say 10ms), poll for write complete (while (eecon1.WR) {}) or use interrupts to tell you.

Performing the read immediately after the write will probably abort the write operation.

The SB manual says a bit about this.

Cheers

Reynard

#3 mityeltu

mityeltu

    Regular

  • EstablishedMember
  • Pip
  • 79 posts
  • Gender:Male
  • Location:Tennessee
  • Interests:Communications

Posted 30 April 2010 - 12:07 PM

You are calling the read function just after you called the write function.

Writing to EEPROM takes time (several ms) so you have to wait for the write cycle to complete first. You can do this by waiting a fixed delay (say 10ms), poll for write complete (while (eecon1.WR) {}) or use interrupts to tell you.

Performing the read immediately after the write will probably abort the write operation.



I inserted a 255ms delay and it still did not write to the eeprom. For whatever reason this function does not work properly. If I gi to using the routine in the data sheet:

eeadr = 0;
eedata = 9;
set_bit&#40;eecon1,2&#41;;
eecon2=0x55;
eecon2=0xaa;
set_bit&#40;eecon1,1&#41;;
clear_bit&#40;eecon1,2&#41;;//this works -- takes 1ms to write, process continues
while &#40;test_bit&#40;eecon1,1&#41;&#41;
{}//wait till finished -- this can be omitted for ongoing processes

everything works fine, but the eeprom_write function does not work corredctly. If you have any other suggestions I am certainly willing to try them. I would rather use what resources I have rather than having to reinvent the wheel -- although, since the c version of the asm stuff from the datasheet works, I may as well just use that, but it still bothers me.... It SHOULD work, and it'll bug me till I figure out WHY it's not working.

Edited by mityeltu, 30 April 2010 - 12:07 PM.




Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users