Hello,
I need to work with serial I2C EEPROM. My MCU is TMS320F28027.
I'm little bit disappointed that plenty of posts on the same topics did not help me.
I prefer version without interrupts (simplicity, linear function, better for bootloader).
The example with interrupts from Control suite uses FIFO, too. It did not work for more than 3 data bytes (FIFO depth 4 bytes) and it is repeatedly sending something on the bus.
The best code I found was this https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/171/3806.5126.I2C_5F00_Writing_5F00_Reading_5F00_EEPROM.txt refered fom
I used it with minor modifications (1 byte address, STP set in the end of function).
void I2C_Read(Uint16 Slave_address, Uint16 Start_address, Uint16 No_of_databytes, Uint16 Read_Array[])
{
//////////////////////////
// Read data from EEPROM//
//////////////////////////
I2caRegs.I2CSAR = Slave_address; //Set slave address
I2caRegs.I2CCNT = 1; //Set count to 2 address bytes
I2caRegs.I2CDXR = Start_address; //Send eeprom high address
I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 0; //Dont release the bus after Tx
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
// I2caRegs.I2CDXR = Start_address & 0xFF; //Send eeprom low address
I2caRegs.I2CCNT = No_of_databytes; //read 5 bytes from eeprom
I2caRegs.I2CMDR.bit.TRX = 0; //Set to Recieve mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
//Stop when internal counter becomes 0
I2caRegs.I2CMDR.bit.STT = 1; //Repeated start, Reception will follow
int i;
for(i = 0; i < No_of_databytes; i++){
while(I2caRegs.I2CSTR.bit.RRDY == 0){}; //I2CDRR not ready to read?
Read_Array[i] = I2caRegs.I2CDRR;
}
I2caRegs.I2CMDR.bit.STP = 1;
}
When I read 4 bytes two time in a sequence I get two different readings. First call reads one more byte.
I2C_Read(0x50, 0xFD, 3, Read_Array);
I2C_Read(0x50, 0xFD, 3, Read_Array2);
So I get {0x10, 0x00, 0xEF} from the first reading and {0xA, 0a10, 0x00} from the second reading.
{0xEF, 0a10, 0x00} follows from the third reading.
So the readings are shifted.
Does anyone have a clue what could be wrong?
