View previous topic :: View next topic |
Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
EEPROM Address |
Posted: Tue Nov 15, 2011 8:44 am |
|
|
18F2620
3.249
To address the EEPROM in the read and write_eeprom functions do I just use the 0x00 to 0x3FF addresses? It's been a while since I've done this and in my research I've found some conflicting info.
EDIT: Just thought to look at the CCS manual, it gives the address as an 8bit number. Kind of tough to address 1024 locations with 8bits?
EDIT2: Looks like they changed the verbiage in later manuals, 8 OR 16bit value depending on part.
Looks like I've got my answer. Just use 0x00 to 0x3FF. Anyone want to confirm?
Thanks,
John |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Nov 15, 2011 9:56 am |
|
|
0x000 to 0x3ff is correct. The exception is when you want to preload the EEPROM with data at programming time. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Tue Nov 15, 2011 9:13 pm |
|
|
Thanks.
I had seen that and that was part of the confusion. I also had some old code that used the wrong approach but worked.
John |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Nov 17, 2011 10:04 am |
|
|
Now I'm trying to program some EEPROM locations prior to run-time. I want to make sure this is the right address. The Programming Spec says:
Quote: | 5.5 Embedding Data EEPROM
Information In the HEX File
To allow portability of code, a PIC18F2XXX/4XXX
family programmer is required to read the data
EEPROM information from the hex file. If data
EEPROM information is not present, a simple warning
message should be issued. Similarly, when saving a
hex file, all data EEPROM information must be
included. An option to not include the data EEPROM
information may be provided. When embedding data
EEPROM information in the hex file, it should start at
address, F00000h. |
So, to put 0xFF in location 0x00 I would:
Code: | #rom 0xF00000 = {0xFF} |
Thanks,
John |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Thu Nov 17, 2011 10:46 am |
|
|
It is correct, but the easiest/safest way, is to use the compiler!...
Code: |
#ROM getenv("EEPROM_ADDRESS") = {0,20,60,45,19,28}
|
This way if you change chip in the future, you don't have to recalculate the address.
Best Wishes |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Thu Nov 17, 2011 1:25 pm |
|
|
Also be careful with the size of the data written to the EEPROM. I remember a project where I was expecting bytes out of the preprogrammed EEPROM but the compiler loaded it as if the data was int16's. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Fri Nov 18, 2011 6:17 pm |
|
|
Thanks for the info. I had seen the getenv in another post and had assumed it was v4 unique. I'll look and see if it is v3 friendly and use it.
I just spent all morning trying to find an addressing problem. I was using int8s in some calculations for address offsets. Only took me about 5 hours to figure out I had to cast them to int16s. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Nov 19, 2011 2:03 pm |
|
|
newguy wrote: | Also be careful with the size of the data written to the EEPROM. I remember a project where I was expecting bytes out of the preprogrammed EEPROM but the compiler loaded it as if the data was int16's. | At least in the v3 compilers the default was to write int16.
Code: | Example to set words (default):
#ROM 0xF00000 = {1, 2, 3, 4, 5}
Example to set bytes:
#ROM int8 0xF00000 = {1, 2, 3, 4, 5}
Example to set a string of bytes:
#ROM 0xF00010 = {"12345"} |
|
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sat Nov 19, 2011 5:35 pm |
|
|
ckielstra wrote: | At least in the v3 compilers the default was to write int16.
|
I just checked the manual. Yup, default is words. Thanks for that info, that would have eaten a good chunk of my life trying to find. |
|
|
|