View previous topic :: View next topic |
Author |
Message |
weg22
Joined: 08 Jul 2005 Posts: 91
|
Still having trouble reading from EEPROM |
Posted: Fri Mar 10, 2006 10:47 am |
|
|
I posted code yesterday for trying to write to and read from a 24FC515 EEPROM chip. The suggestion I got yesterday was that I was only initializing the LOW address byte and was totally neglecting the HIGH address byte. After fixing that error, I'm still having problems. When outputting the value of "data" to the screen through hyperterminal, I get "BBO"??? I should be getting the ASCII equivalent of 24. My code is shown below.
Thanks in advance!
Code: |
#include <16F877.H>
#define eeprom_sda PIN_C4
#define eeprom_scl PIN_C3
#use delay(clock=4000000)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
#use i2c (master, sda=eeprom_sda, scl=eeprom_scl)
main()
{
int i=0, data=0;
i=24;
while(1)
{
// initialize external eeprom
output_float(eeprom_scl);
output_float(eeprom_sda);
// write to eeprom
i2c_start(); // inintializes i2c communication
i2c_write(0xa0); // 10100000
i2c_write(0x0); // initializes HIGH address byte
i2c_write(0x1); // initializes LOW address byte
i2c_write(i); // writes value of "i" to address
i2c_stop();
delay_ms(11);
// read from eeprom
i2c_start();
i2c_write(0xa0); // 10100000
i2c_write(0x0); // initializes HIGH address byte
i2c_write(0x1); // initializes LOW address byte
i2c_start();
i2c_write(0xa1); // 10100001
data=i2c_read(0);
i2c_stop();
putc(data); //prints value of i2c
delay_ms(500);
}
} // end of main
|
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Mar 10, 2006 11:24 am |
|
|
Your code looks like it should work. Now as to the hardware part...
Make sure you have about 4K pull-ups on each of the SDA and SCL lines. Make sure that pin 3, of the eeprom, is tied to VCC(high). Make sure pin 7(WP) is tied to GND(low).
The spec. sheet states that if pin 3 is not tied to VCC that the device will not operate. Pin 7 _can_ be left floating for the device to accept data being written to it but it is not advised. WP is the Write Protect pin that will protect information from being accidentally written to it. This pin needs to be pulled Low to enable the write sequence. A Read can be performed regardless if it is high or low.
I'm not sure if your putc() will format the integer 'data' correctly. Try using printf() to make sure it is formatted properly.
Maybe... printf("%c\n\r", data);.
Ronald |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Fri Mar 10, 2006 11:39 am |
|
|
I use the 24FC515 in a project that I built. I noticed that you do not have a 5ms delay in between the data write and the stop command when you write the PROM. The 515 has a 5ms write delay like other EEPROMs.
Also, make sure that the A2 pin of the memory is tied high, otherwise you'll only be using half the memory. I was caught by this. This different than a 24LC512 (I replaced a 24LC512 with a 515 and found I was only storing half the memory) _________________ The difference between genius and stupidity is that genius has its limits... |
|
|
weg22
Joined: 08 Jul 2005 Posts: 91
|
|
Posted: Fri Mar 10, 2006 12:01 pm |
|
|
It was the 5ms delay that was causing the problem. Thank you very much!!!!! |
|
|
|