This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Write byte to EEPROM using I2C without interrupts

Hello. Below is my function for writing to an LC512 eeprom using the F28335 DSP and I2C without the use of interrupts.

Due to constraints beyond my control, I must use polling and cannot use interrupts for doing reads or writes to the eeprom.
My code below is not writing data correctly. I read back data that is different from what I intended. I am using a known read function that works, so I know the problem is with my write function.

I would appreciate any suggestions or if you see any major errors in how I am do this below.

Thank you,

Chuck

 

// Perform byte write per figure 6-1 on page 11 of 24AA512 EEPROM datasheet

void I2cWriteByte(structI2CMSG *msg)

{
Uint16 i;

I2caRegs.I2CSAR = 0x0050;

// Check if bus busy

if (I2caRegs.I2CSTR.bit.BB == 1)

{

I2caRegs.I2CSAR = 0x0050;

}

for(i=0; i < I2C_NUMBYTES; i++)

{

I2caRegs.I2CCNT = 3; // two bytes for address plus one byte of data to send

I2caRegs.I2CDXR = msg->MemoryHighAddr;

I2caRegs.I2CDXR = msg->MemoryLowAddr;

I2caRegs.I2CDXR = *(msg->MsgBuffer + i);

I2caRegs.I2CMDR.all = 0x6E20; // send start as master transmitter

// wait until communication complete and registers ready

while(I2caRegs.I2CSTR.bit.ARDY == 0){}

msg->MemoryLowAddr++;

if(msg->MemoryLowAddr > 255)

{

if(msg->MemoryHighAddr > 255)

{

// eeprom full. start over at beginning of memory array to overwrite old fault codes.

// for debugging, just stay in this endless loop once 0xFFFF has been reached in EEPROM

}

else

{

msg->MemoryLowAddr = 0x0000;

msg->MemoryHighAddr++;

}

}

// end if(msg->MemoryLowAddr > 255)

}

// end of for loop

}