cancel
Showing results for 
Search instead for 
Did you mean: 

eeprom write

iyenal
Associate II
Posted on July 15, 2004 at 15:22

eeprom write

8 REPLIES 8
iyenal
Associate II
Posted on May 17, 2011 at 12:02

Helo,

I have a problem with upsd.I use upsd3233 and in my application i want to write a byte to eeprom(secondary flash sector) and read.My code is at primary flash(0x0000-0x3FFF). I use 0x4000-0x5FFF address area as eeprom.

When i programed the upsd and run application data is written to destination and can be read back correctly but if second time wrong data has been written.

Here is my code;

#define SECTOR_0_BASE_ADDRESS 0x4000

#define BOOT_FLASH_SECTOR_0_XAAA (volatile unsigned char xdata *)0x5AAA

#define BOOT_FLASH_SECTOR_0_X555 (volatile unsigned char xdata *) 0x5555

void eeprom_write(uint address,uchar data_byte)

{

EA = 0;

// write data byte

*((char xdata *) BOOT_FLASH_SECTOR_0_X555) = 0xAA;

*((char xdata *) BOOT_FLASH_SECTOR_0_XAAA) = 0x55;

*((char xdata *) BOOT_FLASH_SECTOR_0_X555) = 0xA0;

*((char xdata *) SECTOR_0_BASE_ADDRESS) =data_byte;

EA = 1;

*((char xdata *) BOOT_FLASH_SECTOR_0_X555) = 0xF0;// RESET

}

What is wrong with my code?
joseph2399
Associate II
Posted on May 17, 2011 at 12:02

Please take a look at the 3200 EEPROM Emulation example that is available on the Downloads page:

http://www.stmcu.com/modules.php?name=mcu&file=familiesdocs&fam=80

It works well on the DK3200. I suggest you download it and run it on your DK3200 and then take a look at the code.

iyenal
Associate II
Posted on May 17, 2011 at 12:02

thanks for your fast reply,

I tried eeprom emulation code on my DK3200 board it realy works fine but when i add it to my code keil said ''data space overflow'' so i treid to write mine eeprom routine as you see in previos message.
joseph2399
Associate II
Posted on May 17, 2011 at 12:02

Please review the programming flowchart in the data sheet. My first thought is that there is no delay between when you write the byte and then do a reset. In the polling method you have to wait on a bit to change states before the programming cycle is complete. It could be that you are resetting before the programming is complete, so the data doesn't get written properly.

jdaniel
Associate II
Posted on May 17, 2011 at 12:02

milkinis,

While there may be issues with your code writing data correctly, as uPSD suggests, I certainly doubt Keil's compiler would know anything about it. If it's saying something like ''data space overflow'', you probably have your project set to memory model ''small'' in the compiler. Try changing that to large and see if the space overflow goes away. If you like, you could try just specifying individual variables to place in xdata to free up room in the data memory area.

Best Regards,

Phaze426
iyenal
Associate II
Posted on May 17, 2011 at 12:02

Hi Phaze426 and uPSD,

I selected large rom size from target options menu in keil it did not work and i carried all variables to xdata ram it did not work either.

But i solved my problem with erasing sector before writing on it every time. But this is not suitable for my application cause i have to keep more than one bytes (250 bytes) in eeprom so i have to write all other bytes after changing a byte. I do not know is there any way to erase only one byte????

Best Regards,

milkinis
sjo
Associate II
Posted on May 17, 2011 at 12:02

I'm afraid the upsd flash is sector erasable but it is byte writable.

To be efficient you would need to implement a linked-list type array.

I think this is how the app note mentioned works.

Regards

sjo
joseph2399
Associate II
Posted on May 17, 2011 at 12:02

You mentioned that you changed the ''Options for Target'' such that the Code ROM Size setting is ''Large: 64K program''. Did you also try setting the Memory Model from ''Small: variables in DATA'' to ''Large: variables in XDATA''? I suspect that may be where the ''data space overflow'' error results with the combination of your plus the EEPROM Emulation example. I have seen this issue before and by changing the Memory Model setting, the project compiled fine.