Hello,
I have a very simple Matlab 2020b simulink with a single SystemObject block. This block simply calls some hand code which does some I2C transactions. My hand code works as expected when I run it on a 28069 launchpad. However when I run the same I2C code using Simulink Code generation on my 28069 custom board, the code does not work as expected.
The issue is that the I2C interrupt source always returns 0 when my I2C ISR is called. I expect the source to be I2C_ARDY_ISRC or I2C_NACK_ISRC.
}
Uint8 i2cdrvCmdCheckSlavePresent(
Uint8 slaveAddr,
Uint32 timeoutMs)
{
Uint8 isSuccess = !i2cdrvIsBusy();
if (isSuccess)
{
m_state = I2CDRVSTATE_BUSY;
...
I2caRegs.I2CSAR = slaveAddr;
// Enable ARDY and NACK interrupts
I2caRegs.I2CIER.all = 0x0006;
// Mode -> FREE, STT, MST, TRX, RM, IRS all set.
I2caRegs.I2CMDR.all = 0x66A0;
}
return isSuccess;
}
static void _init(void)
{
// Put in reset
I2caRegs.I2CMDR.all = 0x0000;
// Add our interrupt handler to vector table
EALLOW;
PieVectTable.I2CINT1A = &_i2cInt1AISR;
EDIS;
// Enable I2C interrupts in the PIE: Group 8 interrupt 1 and 2
PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
//PieCtrlRegs.PIEIER8.bit.INTx2 = 1;
// Enable CPU INT8 which is connected to PIE group 8
IER |= M_INT8;
// Set our own address
I2caRegs.I2COAR = 0x0001;
// Clocks
I2caRegs.I2CPSC.all = CLK_PRESCALE;
I2caRegs.I2CCLKL = CLK_LOW;
I2caRegs.I2CCLKH = CLK_HIGH;
// Disable all ints
I2caRegs.I2CIER.all = 0x0000;
// Take out of reset
I2caRegs.I2CMDR.bit.IRS = 1;
}
// I2C-1A Interrupt - handles the basic I2C
static interrupt void _i2cInt1AISR(void)
{
// Read interrupt source
Uint16 intSrc = I2caRegs.I2CISRC.all; //this is always returning 0. it should return I2C_NACK_ISRC or I2C_ARDY_ISRC
switch(intSrc)
{ .... }
}
I think I2caRegs.I2CISRC is not being updated because by the time the ISR is called the I2C module is in reset mode. Using the debugger I see that at the end of the i2cdrvCmdCheckSlavePresent() function the reset mode is off and interrupts are enabled.

When I enter i2cInt1AISR() I see that the I2C module is in reset. When I run this I2C hand code on the launchpad, I2caRegs.I2CMDR.bit.IRS is always 1.

Could the I2C module entering reset mode be why the interrupt source always returns 0? Or could the module clock freq, or SDCLK period in my init function be the cause of this?
I set a read watchpoint on I2caRegs.I2CMDR.bit.IRS so see what is writing to that register. Only the _init() function should be writing to I2CMDR. For some reason with the watchpoint attached, the ISR always correctly shows the interrupt source to be NACK or ARDY.
