CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Still having trouble reading from EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
weg22



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

Still having trouble reading from EEPROM
PostPosted: Fri Mar 10, 2006 10:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 10, 2006 11:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 10, 2006 11:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 10, 2006 12:01 pm     Reply with quote

It was the 5ms delay that was causing the problem. Thank you very much!!!!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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