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

Need Help Writing/Reading to/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

Need Help Writing/Reading to/from EEPROM???
PostPosted: Thu Mar 09, 2006 4:07 pm     Reply with quote

Hi all,

I am using a PIC16F877 to write to an external EEPROM chip (24FC515). I have went through the PIC C example ex_extee.c and have attempted to mimic it in order to:

(a) write the value 24 to address 0x1 of the eeprom chip
(b) read the value previously written to 0x1 and display it thru hyperterminal

The result displayed in hyperterminal is an ASCII char equivalent to 0x7f or 127. I think I even changed the value I'm storing in memory from 24 to other numbers and still got an output of 127 in HT. My code is listed below.

Thanks in advance for any help!

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 - last digit det to read/write
        i2c_write(0x1);      // initializes address (mike forgot this)
        i2c_write(i);      // writes value of "i" to address
        i2c_stop();
        delay_ms(11);

        // read from eeprom
        i2c_start();
        i2c_write(0xa0);      // 10100000 - last digit det to read/write
        i2c_write(0x1);
        i2c_start();
        i2c_write(0xa1);      // 10100001 - last digit det to read/write
        data=i2c_read(0);
        i2c_stop();

        putc(data);      // displays value in HT
       
        delay_ms(500);
    }
} // end of main
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 09, 2006 4:45 pm     Reply with quote

Your protocol is wrong. You have to send two address bytes to the
24FC515. I suggest that you use the CCS driver file 24515.C, which
is in c:\Program Files\Picc\Drivers
weg22



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

PostPosted: Thu Mar 09, 2006 5:31 pm     Reply with quote

I don't have the 24515.c file - I have an older version of the software. Is it identical to the 2465.c file where you have:

Code:

i2c_write(hi(address));
i2c_write(address);


Thanks again
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