|
|
View previous topic :: View next topic |
Author |
Message |
Spanska Guest
|
Problem using EEPROM read/write functions |
Posted: Sun Sep 04, 2005 4:48 pm |
|
|
I tried using the program in that post and it doesn't work. The one in the reply of PCM programmer.
http://www.ccsinfo.com/forum/viewtopic.php?t=17590
It keeps reading FF after the two writes. It worked sometimes with some other code. For example I put the power to the circuit, it writes correctly. I remove the power, put it back and there are other values in the EEPROM. I tried reprogramming the PIC many times, looked carefully at the configuration bits, etc. What else could I try?
Thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 04, 2005 5:18 pm |
|
|
1. Are you running the program in hardware or a simulator ?
2. Are you using a 16F877 ? If not, what PIC are you using ?
3. What is your crystal frequency ?
4. What is your version of the compiler ?
This will be a number such as 2.734, or 3.191, or 3.233, etc.
5. You probably modified the program. Post the complete program
that you're using, including the #fuses statement, etc. |
|
|
Spanska Guest
|
|
Posted: Sun Sep 04, 2005 6:23 pm |
|
|
1. I'm using the program in hardware using MPLAB IDE v6.60 to put it into the PIC using the Picstart Plus programmer with firmware version 4.20.3
2. I'm using a PIC16F873-20/SP
3. I'm using a 10MHz crystal with two 22pF capacitors
4. I'm using the PCW compiler.
IDE version 3.24
PCB version 3.139
PCM version 3.139
PCH version 3.139
5. I modified it a bit, yes, because I didn't have the same PIC and wasn't using the same crystal either.
Code: |
#include <16F873.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 10000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
//===========================================
main()
{
printf("Start\n\r\n\r");
write_eeprom(0, 0x55);
printf("Wrote 0x55 to eeprom address 0\n\r");
printf("Read %X\n\r", read_eeprom(0));
printf("\n\r");
write_eeprom(0, 0xAA);
printf("Wrote 0xAA to eeprom address 0\n\r");
printf("Read %X\n\r", read_eeprom(0));
printf("\n\rDone\n\r");
while(1);
}
|
Thank you for your quick answer! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 04, 2005 7:34 pm |
|
|
I can't get your version of the compiler to display RS-232 output.
You'll have to wait until I get back into the office on Monday or Tuesday.
I have the equipment there to work with older versions. |
|
|
dromero
Joined: 05 Sep 2005 Posts: 3
|
Re: Problem using EEPROM read/write functions |
Posted: Mon Sep 05, 2005 8:53 am |
|
|
Spanska wrote: | I tried using the program in that post and it doesn't work. The one in the reply of PCM programmer.
http://www.ccsinfo.com/forum/viewtopic.php?t=17590
It keeps reading FF after the two writes. It worked sometimes with some other code. For example I put the power to the circuit, it writes correctly. I remove the power, put it back and there are other values in the EEPROM. I tried reprogramming the PIC many times, looked carefully at the configuration bits, etc. What else could I try?
Thank you! |
What other code did it work with? And what was your reason for removing power? |
|
|
Spanska Guest
|
|
Posted: Mon Sep 05, 2005 9:00 am |
|
|
With the code in that post it worked once.
http://www.ccsinfo.com/forum/viewtopic.php?t=19607
Probably because of the #rom statement at the beginning. When I try to read the values a second time, some are different now. When I try to overwrite them, to keep their old values. Such a weird problem...
I removed power to reset the PIC and see if it would keep the values. They seem to tend to go back to all FF's after a few power resets. |
|
|
Spanska Guest
|
|
Posted: Mon Sep 05, 2005 9:54 am |
|
|
I did some other tests to show you what really happens. At first I go to the Programmer menu, then to Read. I wait then go to View and choose EEPROM. I see FF's everywhere. I take that code:
Code: |
#include <16F873.H>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(Clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, Errors)
// Put some data into internal EEPROM.
#rom 0x2100 = {0x55, 0xAA, 0x01, 0x23, 0x45, 0x67, 0x89}
//=========================================
main()
{
char value;
char addr;
// Read the internal data eeprom and display the values.
for(addr = 0; addr < 7; addr++)
{
value = read_eeprom(addr);
printf("%x ", value);
}
printf("\n\r");
while(1);
}
|
and program it into my PIC. Then if I go again to View and EEPROM. I see
from 0000 to 0006: 55 AA 01 23 45 67 89 and all FF's for the other one. Fine seems to work now. After a couple of power reset, everything looks fine.
Then I try this code:
Code: |
#include <16F873.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 10000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
//===========================================
main()
{
printf("Start\n\r\n\r");
write_eeprom(0, 0x66);
printf("Wrote 0x66 to eeprom address 0\n\r");
printf("Read %X\n\r", read_eeprom(0));
printf("\n\r");
write_eeprom(0, 0x99);
printf("Wrote 0x99 to eeprom address 0\n\r");
printf("Read %X\n\r", read_eeprom(0));
printf("\n\rDone\n\r");
while(1);
}
|
I verify the EEPROM mem just to make sure. Same thing as before. Perfect. Then I put the PIC on the breadboard and see what happens.
Start
Wrote 0x66 to eeprom address 0
Read 55
Wrote 0x99 to eeprom address 0
Read 55
Done
A little power reset... Here we go FF at both readings now!
Even after many other power resets (removing the power from the board, putting it back in) I still see FF for both readings.
Then, I remove the PIC from the board, put it in the programmer. Go to Programmer, Read, then to View, EEPROM and the first location is really FF and all the other ones haven't changed. What am I doing wrong?
Ok now, I took a brand new chip of the same type. All the same writings on it. I read it's EEPROM content. 00's for all locations. I program it with the second program.
I put it on the board, put the power to it and...
Start
Wrote 0x66 to eeprom address 0
Read 00
Wrote 0x99 to eeprom address 0
Read FF
Done
I remove the power from the board, put it back.
Start
Wrote 0x66 to eeprom address 0
Read FF
Wrote 0x99 to eeprom address 0
Read FF
Done
and it stays the same even if I do it again. So my problem is probably not the chip itself.
I put the chip back into the programmer. First location of EEPROM is FF and still 00 for all the other locations.
read_eeprom seems to work fine. Not write_eeprom though. Hopefully that should give you more details of the problem.
Could it be the wiring on the board? For the ground and Vcc links I didn't put any capacitor. Just a short cable to the ground and power rails. As I already said, I used two 22pF capacitors with my 10MHz crystal. For the MCLR pin I used only a resistor connected directly to the power rail. For RS232 communications I use a special module, but it's working fine. On the second pin (AN0) I have a short cable, then a 1k resistor and a 20Mohm pot. That was for some testing with the ADC. Even if I unplug the cable it doesn't change anything for the EEPROM issues, hopefully. I'm learning so chances are I won't have as many ideas of tests I could do as you would (unless you're learning too )
Again, thank you for your time! |
|
|
Spanska Guest
|
|
Posted: Mon Sep 05, 2005 10:13 am |
|
|
I found some upgrade file in my CCS folders on a backup and now I have PCWH. IDE version 3.219. PCB version 3.219. PCM version 3.219. PCH version 3.219. The same thing happens with the second program. I just see FF. |
|
|
Spanska Guest
|
|
Posted: Mon Sep 05, 2005 11:10 am |
|
|
I also just upgraded MPLAB to v7.21 and the PICSTART Plus firmware to version 4.40.1
Still the same results... |
|
|
dromero
Joined: 05 Sep 2005 Posts: 3
|
eeprom |
Posted: Mon Sep 05, 2005 12:13 pm |
|
|
I ran your second program (writing twice to location 00) using an older PICSTART plus and and older version of MPLAB on a PIC16F877, and it did exactly what it was supposed to: MPLAB viewing the EEPROM window showed 99 at location 00, alll other locations the same.
Since you're just witing internally, it's hard for me to picture how external circuitry could be involved. I've seen several posts where it appeared that newer versions of the compiler introduced bugs that weren't there before. BTW, my version is 3.214, if that's any help.............. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|