View previous topic :: View next topic |
Author |
Message |
weg22
Joined: 08 Jul 2005 Posts: 91
|
Need Help Writing/Reading to/from EEPROM??? |
Posted: Thu Mar 09, 2006 4:07 pm |
|
|
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
|
|
Posted: Thu Mar 09, 2006 4:45 pm |
|
|
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
|
|
Posted: Thu Mar 09, 2006 5:31 pm |
|
|
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 |
|
|
|