View previous topic :: View next topic |
Author |
Message |
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
#rom on PIC18F8722 |
Posted: Sun Apr 06, 2008 9:33 pm |
|
|
I am trying to use the #rom to preload my eeprom with values. I have added
#rom int8 0xF00000={0x61}
to the beginning of my program and then in the body, i am reading the eeprom
read=read_eeprom(0);
However, when i look at what is in read, i find that it is 0xFF instead of 0X61. I do not see what i am doing incorrectly. I have looked at the forum and it appears that it should be as simple as i have done, but i am not getting the right values.
V 4.050 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 06, 2008 10:17 pm |
|
|
Post a short test program that has a #rom statement and read_eeprom()
statement, and a printf() statement to display the values that were read.
Be sure to post the #include, #fuses, and #use delay() statements,
and a while(1) statement at the end of main(). (10 lines of code, max). |
|
|
Matro Guest
|
|
Posted: Mon Apr 07, 2008 6:40 am |
|
|
Your code is right because by importing the hex of the following code
Code: |
#include <18F8722.h>
#ROM int8 0x700000 = {0x61}
void main()
{
while(1);
}
|
in MPLAB and looking at the EEPROM I can see the 0x61 in the first EEPROM byte.
What programming software are you using?
Matro. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Mon Apr 07, 2008 11:39 am |
|
|
I have am using the CCS bootloader and i am loading the program hex file with the SIOW.exe out of the CCS compiler. I noticed you have 0x700000 as the #Rom address. is this a typo or does the 18F8722 have a different location for the eeprom?
PCM programmer- I will try your suggestion, i just have not gotten to it yet. |
|
|
Matro Guest
|
|
Posted: Mon Apr 07, 2008 11:48 am |
|
|
My mistake. I've done some tests with some devices and copy my last test...
The address is 0xF00000 for that device too.
Sorry for the mistake.
Matro. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 07, 2008 11:49 am |
|
|
This thread has an example of a test program for the internal eeprom.
You just need the first part, where it reads and displays the values that
were set with the ROM statement.
http://www.ccsinfo.com/forum/viewtopic.php?t=32722
The address of the data eeprom is usually given in the Programming
Specification for the PIC. Here's section in the spec for the 18F8722:
Quote: | 5.5 Embedding Data EEPROM Information in the HEX File
When embedding data EEPROM information
in the hex file, it should start at address F00000h.
|
Here's how to find and download the specs:
Go to the Microchip Data Sheet Finder page (bookmark this page):
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2046
Select your PIC in the drop-down box. Wait for the page to load.
Then locate the link for the Programming Spec and download it. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Mon Apr 07, 2008 12:11 pm |
|
|
Thanks. I was reading through the data sheet and either skipped over that or did not read that part of Setion 5. Looks like i am doing the #rom correctly, i can also write to and read from eeprom in the program, so it is something else that is causeing the #rom not to work. I have to review my fuses and the rest of the set up of the program. |
|
|
Matro Guest
|
|
Posted: Mon Apr 07, 2008 12:25 pm |
|
|
Since SIOW is a program dedicated to serial communication, I guess you're using a bootloader to program the PIC.
If this is the case, everything's normal because a bootloader doesn't take in charge the EEPROM programming.
Have I correctly understood what's your programming software flow?
Matro. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Mon Apr 07, 2008 12:46 pm |
|
|
You are correct. I program the main code through the serial port into the PIC. |
|
|
Matro Guest
|
|
Posted: Mon Apr 07, 2008 12:58 pm |
|
|
nmeyer wrote: | You are correct. I program the main code through the serial port into the PIC. |
So you are using a bootloader that isn't able to program the EEPROM (like almost all bootloaders).
So it's normal that you read 0xFF in EEPROM (0xFF is default value i.e. the value of a never used chip or an erased one).
Matro. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Mon Apr 07, 2008 1:52 pm |
|
|
So, then to use the #rom, i will have to use that in the bootloader code instead of my main program. |
|
|
Matro Guest
|
|
Posted: Mon Apr 07, 2008 2:04 pm |
|
|
I don't know your exact project but according to your needs and skills, you can :
- program your PIC with a ISP programmer if it is possible in your context
- modify the bootloader code for it to manage EEPROM writing (and you probably need to create your own PC application)
- locate your data in program memory instead of EEPROM memory.
Matro. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Apr 08, 2008 1:50 am |
|
|
Rather than using the #rom directive you can initialise the eeprom with a bit of code.
Knowing that erased eeprom = 0xFF you just need to use a byte of eeprom to store a version number. At the start of your main program just read this and if it is not at the revision you require write default values to eeprom and write a new version number to that address. This way if you need to write new default values to eeprom then you can compare the version number.
This will also offer protection against loss of eeprom data (erase). because each time your code starts it will read the version number and if it is 0xFF it will just re-write the default values back in. With doing it using the #ROM way if the eerpom gets erased somehow you will have to re-program it.
If these values are fixed and will never change then just use program memory instead of eeprom. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Tue Apr 08, 2008 7:14 am |
|
|
That is what i am planning to do for now. The values in eeprom are set to "default" at first power up and then the user can at that point go through all of them and change them and save them back to eeprom to use unitl they change them again. |
|
|
|