View previous topic :: View next topic |
Author |
Message |
ancient_one
Joined: 05 Jan 2012 Posts: 7
|
Writing (not overwriting) to eeprom |
Posted: Mon Mar 05, 2012 7:05 pm |
|
|
I'm using PIC16F88 and i've got a file that store a lot of bytes in eeprom
Code: | const byte asciitable1[51][5] = {0x00, 0x00, 0x00, 0x00, 0x00, // 32 SPACE
0x00, 0x00, 0x7d, 0x00, 0x00, // 33 !
0x00, 0x70, 0x00, 0x70, 0x00, // 34 "
0x14, 0x7f, 0x14, 0x7f, 0x14, // 35 #
.... |
Now i need to write&read a data struct into eeprom at runtime, how can i find a free address that will not overwrite my asciitable const?
I use:
Code: | typedef struct {
unsigned char string[32];
int8 hscroll;
int8 vscroll;
} packet;
void write_eeprom_packet()
{
int8 i;
for (i = 0; i < sizeof(packet); i++)
write_eeprom(EEPROMADDRESS+i, *(p+i));
}
void read_eeprom_packet()
{
int8 i;
for (i = 0; i < sizeof(packet); i++)
*(p+i) = read_eeprom(EEPROMADDRESS+i);
} |
I need to know a free address for EEPROMADDRESS[/code] |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Mar 05, 2012 8:00 pm |
|
|
There is no concept of memory management or file system management for the EEPROM. You, as the application developer decide where you place content in the EEPROM. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 05, 2012 10:47 pm |
|
|
Quote: | const byte asciitable1[51][5]
|
This array is stored in flash memory. That is not the same type of
memory as Data EEprom. The write_eeprom() and read_eeprom()
functions do not operate on Flash memory.
The write_eeprom() and read_eeprom() functions operate on Data EEprom. The 16F88 has 256 bytes of Data EEprom, so those two
functions expect an address of 0 to 255.
You can just choose 0 as the starting address for your 34-byte packet.
Put the packet at the start of the Data EEprom. Example:
Code: |
#define EEPROMADDRESS 0
|
|
|
|
Can
Joined: 26 Feb 2012 Posts: 23
|
|
Posted: Thu Mar 08, 2012 3:20 am |
|
|
If i understand your question right you can just allocate the first byte of the EEPROM for memory mapping. Whenever you write to EEPROM, you can just update the memory map. So whenever you read the first byte in the EEPROM you have your last written address (or if you make a +1 you get the first available address)
Best |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Mar 08, 2012 1:38 pm |
|
|
from my hard won experience , i might add data EEPROM has plenty of opportunities to give you grief.
1- the TIME to do a write is significant compared to nearly any other CCS intrinsic function- and you NEVER want to do a data eeprom write from inside an ISR
2- eeprom is FRAGILE , and an excessive number of writes can leave
addresses nonfunctional
3- without a decently robust means of TESTING that a given location is data and not trash - you ought to allocate an extra byte or word to verifying the
integrity of what you wrote -i am speaking of checksum ( byte or word ) or CRC test -otherwise you are courting trouble over the very long haul
just my 2 cents |
|
|
|