I'm using a TMS320 launchpad board to try to talk to a simple external device. This device's default setup is that it is ready with data, all you have to do is address the device, select the register (reg 0) and read two bytes of data.
Having had problems with stop conditions failing to be generated in FIFO mode I have set the 320 up to have normal mode and Repeat Message, which, as I understand it, gives manual control over the generation of stop conditions.
So what we should see is address 0x48 writing to register 0, then another message with the same address and reading back two bytes, but the stop condition occurs before the second byte is sent. I put a breakpoint in CCS on the section of code that generates the stop condition and it never hits it. How can the I2C module generate its own stop condition?
You can see the second red blob indicating a stop condition.
The code looks like this:
bool hal_I2CMasterRx( uint8_t MsgLength )
{
static bool MsgStarted = false;
bool MsgFinished = false;
static uint8_t RxByte = 0;
uint16_t Dly = 1000;
I2caRegs.I2CSAR = 0x48;
if( MsgStarted )
{
if( BytesToSend == 0 )
{
if( I2caRegs.I2CSTR.bit.XRDY ) // has it finished the last byte?
{
I2caRegs.I2CSTR.bit.XRDY = 1;
RxData[ RxByte ] = I2caRegs.I2CDRR;
RxByte++;
I2caRegs.I2CMDR.bit.STP = 1; // send a stop condition
MsgStarted = false; // A BREAKPOINT HERE NEVER GETS HIT
MsgFinished = true;
}
}
else
{
if( I2caRegs.I2CSTR.bit.XRDY ) // are we ready to Tx?
{
// I2caRegs.I2CSTR.bit.XRDY = 1;
RxData[ RxByte ] = I2caRegs.I2CDRR;
RxByte++;
I2caRegs.I2CDXR = 0;
BytesSent++;
BytesToSend--;
}
}
}
else
{
if( I2caRegs.I2CSTR.bit.SCD )
{
I2caRegs.I2CSTR.bit.SCD = 1;
}
if( I2caRegs.I2CSTR.bit.BB == 0 ) // wait for bus busy = false
{
I2caRegs.I2CMDR.bit.MST = 1; // set Master mode
I2caRegs.I2CMDR.bit.RM = 1;
I2caRegs.I2CMDR.bit.STT = 1; // send Start condition
I2caRegs.I2CMDR.bit.TRX = 0; // receive (read) mode
if( I2caRegs.I2CSTR.bit.XRDY ) // are we ready to Tx?
{
while( Dly-- )
{}
// I2caRegs.I2CSTR.bit.XRDY = 1;
Status[BytesToSend] = I2caRegs.I2CSTR.all;
RxByte = 0;
MsgStarted = true;
BytesToSend = MsgLength;
I2caRegs.I2CDXR = 0;
BytesSent++;
BytesToSend--;
}
}
}
return MsgFinished;
}
Any help you can give me on this would be appreciated.