Brennan Dayberry

programming EEPROM

Discussion created by Brennan Dayberry on Feb 24, 2008
Latest reply on Mar 29, 2008 by Anu Radha
I have closely followed AN2400 for guidance in using the EEPROM, and have it mostly functional. In the AN2400 document the C code to write data to an address is: *progAddr = data; with progAddr being defined as UINT* 16 and data UINT 16. By looking at another post on these forums I ended up accomplishing this in my own code as:

*(volatile unsigned char*)0x1400 = data;

with 0x1400 being the first address of EEPROM for my device(MC9S08DZ60) and data being defined as an int, with: typedef unsigned int word;

When data is an int less than 255, a byte, everything writes fine. And when reading the data back with:

data = *(volatile unsigned char*)0x1400;

data is correct.

However, when data is more than 255, it ends up writing as the original data-255-1, and gets recalled as such. When I change the dereferenced pointer to:

*(volatile unsigned int*)0x1400 = data;

in the any of the functions, it compiles but in debug everything fails and the error bits get set in FSTAT. Any suggestions?

Message Edited by bdayberr on 2008-02-24 12:52 AM