View previous topic :: View next topic |
Author |
Message |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
EEPROM problem |
Posted: Fri Apr 09, 2010 12:40 pm |
|
|
Has anything changed with the compiler or I'm I going crazy?
I'm using a PIC16F88 with 256 bytes of internal eeprom and ver 4.106 of the compiler I am trying to write to five different eeprom memory locations as shown below:
Code: |
#define DAC0 0
#define DAC1 20
#define DAC2 40
#define DAC3 60
#define DAC4 80 |
but when I read each location I am gettin a bogus int8 value, I have used these routines below in the past 1000 times without a problem, but what is different now?
These are the routines:
Code: | int16 read_int16_eeprom(int8 address) | or
Code: | int16 read_int16_eeprom(int16 address) |
the same applies to the write;
Code: | void write_int16_eeprom(int8 address, int16 data) | or
Code: | void write_int16_eeprom(int16 address, int16 data) |
The actual functions from CCS internal_eeprom driver:
Code: | int16 read_int16_eeprom(int16 address)
{
int8 i;
int16 data;
for(i = 0; i < 2; ++i)
{
*(&data + i) = read_eeprom(address + i);
}
return(data);
}
void write_int16_eeprom(int16 address, int16 data)
{
int8 i;
for(i = 0; i < 2; ++i)
{
write_eeprom(address + i, *(&data + i));
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 09, 2010 12:56 pm |
|
|
Those are not the functions from the internal_eeprom.c file for vs. 4.106.
They might be from some very early version of 4.xxx, or from vs. 3.
Look at the internal_eeprom.c file in this directory:
Quote: |
c:\program files\picc\drivers\internal_eeprom.c
|
This is what the functions for vs. 4.106 look like. Notice that they
cast the int16 (or int32) pointer to a byte-pointer, before they do
pointer arithmetic on it. That's critical. It's needed to get the
correct address. That's why your code doesn't work.
Quote: |
int16 read_int16_eeprom(INT_EEPROM_ADDRESS address)
{
int8 i;
int16 data;
for(i = 0; i < 2; ++i)
{
*((int8 *)(&data) + i) = read_eeprom(address + i);
}
return(data);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Fri Apr 09, 2010 1:33 pm |
|
|
Thank you PCM programmer,
After looking at it for awhile I realized what the issue was:
It is trying to hadle data (as declared )int16, but we are trying to separate the data as two bytes so the pointer should be : *((int8*)&data
I made the following change as below:
void write_int16_eeprom(int16 address, int16 data)
{ int8 i;
for(i = 0; i < 2; i++)
{
write_eeprom(address + i, *((int8*)&data + i));
}
}
And everything is happy now! That should teach me not to trust some of the files from the CCS drivers directory, I basically just copied the file and called it out in my program, but nothing seemed to work. I am not sure. The file in question (internal_eeprom.c) that I have has a date code of 4/6/2007 so perhaps it was an old screwed up file?
Thanks once again! |
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Fri Apr 09, 2010 1:43 pm |
|
|
Where do you get the new folder with all the updated driver files?
I do frequent updates (very scary!!) and none of these seem to have been updated, the file that I used came from my CD rom install that CCS sent to me late last year with ver 4.0XX I just checked on that and I do not have the updated file. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 09, 2010 1:50 pm |
|
|
It should be updated when you do an install.
Do this test. (I just did it).
Open a DOS window and delete the driver file
Quote: |
c:\Program Files\PICC\Drivers>del internal_eeprom.c
|
Then go to whereever you have your CCS updates stored, and run
the one for vs. 4.106. In the example below, I'm running pcm4106.exe:
Quote: |
c:\Downloads\CCS\pcm4106
|
After it installs, go do a 'dir' on that file in the drivers directory:
Quote: |
c:\Program Files\PICC\Drivers>dir internal_eeprom.c
|
Here is the result. It's right there. It's installed.
Code: |
Volume in drive C has no label
Volume Serial Number is 1053-12EA
Directory of C:\Program Files\PICC\Drivers
INTERN~1 C 6,927 04-06-07 12:40p internal_eeprom.c
1 file(s) 6,927 bytes
0 dir(s) 48,562.03 MB free
|
Check if you moved a copy of the driver file into your local project
directory. If so, it will never be updated unless you manually copy
over the latest file from the Drivers directory into your Local directory. |
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Fri Apr 09, 2010 2:13 pm |
|
|
I wonder if this has to do with the fact that I DO NOT use the CCS default directory, for the last 12 years I have been installing my CCS updates to : C:\PICOMP\
Not to c:\Program Files\PICC\ |
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Fri Apr 09, 2010 2:31 pm |
|
|
Very interesting!! but I have no idea to what is going on?
PCM programmer, I did exactly as you did from the dos prompt I went into the drivers directory and removed the internal_eeprom.c dated 4/6/07 This was the defective file.
Then I re-installed the latest version PCDWH 4.106 (BTW, there is no problem if you install to a different directory)
Went back to the driver directory; and there was the "internal_eeprom.c "
file, but the date and time is identical to the one I deleted????
when I opened the file it had the correct fixes
Can you explain this one to me? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Fri Apr 09, 2010 2:37 pm |
|
|
The paths used for the include files, are settable via the 'Options', 'Project Options', 'Include files' tab.
If you have copies installed into multiple directories, you need to change these, or they will stay pointing at the location of the include files, when the project was first created.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|