Hello,
The below function only writes 4 bytes to the eeprom via I2C before returning to main() without writing the remaining 10 bytes.
Due to constraints, I have to create a write function for I2C to write data to the eeprom via I2C without the use of interrupts.
Can anyone give me a suggestion on how to get this code to work? I have tried checking for the NACK bit and it doesn't
seem to work.
Thank you,
Chuck
// Perform byte write per figure 6-1 on page 11 of 24AA512 EEPROM datasheet
void I2cWriteByte(struct I2CMSG *msg)
{
Uint16 i;
I2caRegs.I2CMDR.bit.IRS = 0;// disable I2C module during configuration
I2caRegs.I2CCNT = 3; // two bytes for address plus one byte of data to send
I2caRegs.I2CSAR = 0x0050; // slave address
I2caRegs.I2CMDR.all = 0x6E30; // send start as master transmitter and take I2C module out of reset
for(i=0; i < I2C_NUMBYTES; i++)
{
if (I2caRegs.I2CSTR.bit.SCD == 1)
{
I2caRegs.I2CMDR.bit.IRS = 0;// disable I2C module during configuration
I2caRegs.I2CCNT = 3; // two bytes for address plus one byte of data to send
I2caRegs.I2CSAR = 0x0050; // slave address
I2caRegs.I2CMDR.all = 0x6E30; // send start as master transmitter and take I2C module out of reset
}
while(I2caRegs.I2CSTR.bit.NACK == 1)
{
I2caRegs.I2CMDR.bit.STP = 1; // send start as master transmitter
I2caRegs.I2CCNT = 1;
I2caRegs.I2CDXR = 0x50;
I2caRegs.I2CSTR.bit.NACK = 1;
}
if(I2caRegs.I2CSTR.bit.BB == 0)
{
I2caRegs.I2CDXR = msg->MemoryHighAddr; // high byte of address
I2caRegs.I2CDXR = msg->MemoryLowAddr; // low byte of address
I2caRegs.I2CDXR = *(msg->MsgBuffer+i); // data byte
msg->MemoryLowAddr++; // increment low byte of address
}
} // end of for loop
} // end of I2cWriteByte()