Jump to content
mityeltu

Eeprom Routines

Recommended Posts

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: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
1,	 /* Use busy signal: 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(void);

void main()
{
mcu_setup();

//writing does not work
adr = 0x10;
dat = 0x01;
eeprom_write(adr,dat);

adr = 0x00;
one = eeprom_read(adr);
lprintf("m:");
one = one + 48;
lcd_write(one);
while(1)
{}
}


void mcu_setup()/**********************************MCU_SETUP***********************************/
{
intcon = 0x00;
adcon0 = 0;
ansel = 0;
anselh = 0;

trisa = 0xff;//porta inputs
trisb = 0x00;//portb outputs - lcd data
set_bit(trisb,0);//input for int0 -- not used
trisc = 0x00;//portc output
portc = 0;
trisd = 0x00;//portd output
portd = 0;
trise = 0xff;//porte input

lcd_setup();
}////////////////////////////////////////////////END MCU_SETUP////////////////////////////////////

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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(eecon1,2);
eecon2=0x55;
eecon2=0xaa;
set_bit(eecon1,1);
clear_bit(eecon1,2);//this works -- takes 1ms to write, process continues
while (test_bit(eecon1,1))
{}//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

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×