I think I should be able to read and write the 24LC256 I'm using with the following code:
But, by watching data in debug mode, I get an FF instead of the 25 I think should be reading.
I think I've done everything according to the datasheet (http://www.datasheetcatalog.org/datasheet2/7/0yuw0yc3x0278cpz78zge08qi13y.pdf), even exchanging the chip selection bits to 000 or 111 if it might be the problem, and I guess the schematic is right (I'm showing it anyway).
Any idea of what can be wrong?
Thanks.
Code:
#include <p18f4620.h>
#include <i2c.h>
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config LVP = OFF
#pragma config XINST=OFF
#pragma config OSC=INTIO67
#define CLOCK_FREQ (80000000ul) // Hz
void main(void)
{
char data;
OpenI2C(MASTER, SLEW_OFF);
StartI2C();
WriteI2C(0b10100000); //control byte
WriteI2C(0b00000000); //adr hi
WriteI2C(0b00000000); //adr lo
WriteI2C(0x25); //data 0
StopI2C();
StartI2C();
WriteI2C(0b10100001); //control byte (read data)
WriteI2C(0b00000000); //adr hi
WriteI2C(0b00000000); //adr lo
data=ReadI2C();
StopI2C();
}
But, by watching data in debug mode, I get an FF instead of the 25 I think should be reading.
I think I've done everything according to the datasheet (http://www.datasheetcatalog.org/datasheet2/7/0yuw0yc3x0278cpz78zge08qi13y.pdf), even exchanging the chip selection bits to 000 or 111 if it might be the problem, and I guess the schematic is right (I'm showing it anyway).
Any idea of what can be wrong?
Thanks.
Last edited: