Hello All,
I am using the 28388D Control Card and trying to get the I2C comm's working with Simulink Embeded coder,
I first started with the CCS C code I2C example and with modification to the data packets got this running with no problem, a very simple code with a single device with writing & reading to 5 registers in the chip. so can prove the HW is working correctly.
The final software design will be done in Simulink Embeded coder issue I am having an issue with this design. Trying to use the Embeded I2C blocks rather than using custom code/s-functions.
After generating the code and running the code on CCS and debugging, I2C is receiving messages but not sending them.
The issue seems to be with the line "while (I2caRegs.I2CFFTX.bit.TXFFST!=0 && tx_loop<10000 )" where the TXFFST is never equal to zero. Is there something in Simulink I am missing to clear this?
Below is the model setup


Generated code for the blocks
if (rtb_Compare) {
/* S-Function (c280xi2c_tx): '<S9>/I2C Transmit' incorporates:
* Constant: '<S3>/Control Reg2'
*/
{
int unsigned tx_loop= 0;
I2caRegs.I2CFFTX.bit.TXFFIENA = 0;/* Disable Tx Fifo interrupt*/
while (I2caRegs.I2CFFTX.bit.TXFFST!=0 && tx_loop<10000 )
tx_loop++;
if (tx_loop!=10000) {
I2caRegs.I2CSAR.bit.SAR = 0; /* Set slave address*/
I2caRegs.I2CCNT= 1; /* Set data length */
/* mode:1 (1:master 0:slave) Addressing mode:0 (1:10-bit 0:7-bit)
free data mode:0 (1:enbaled 0:disabled) digital loopback mode:0 (1:enabled 0:disabled)
bit count:0 (0:8bit) stop condition:1 (1:enabled 0: disabled)*/
I2caRegs.I2CMDR.all = 28192;
tx_loop= 0;
while (I2caRegs.I2CFFTX.bit.TXFFST==16 && tx_loop<10000)
tx_loop++;
if (tx_loop!=10000) {
I2caRegs.I2CDXR.bit.DATA = (uint8_T)IPDM_Rev_A0_P.ControlReg2_Value;
}
}
I2caRegs.I2CFFTX.bit.TXFFIENA = 1;/* Enable Tx Fifo interrupt*/
I2caRegs.I2CFFTX.bit.TXFFINTCLR = 1;/* Clear Tx interrupt flag*/
}
/* S-Function (fcgen): '<S6>/Function-Call Generator' incorporates:
* SubSystem: '<S6>/StartRead'
*/
/* S-Function (c280xi2c_tx): '<S8>/I2C Transmit' incorporates:
* Constant: '<S6>/Constant1'
*/
{
int unsigned tx_loop= 0;
I2caRegs.I2CFFTX.bit.TXFFIENA = 0;/* Disable Tx Fifo interrupt*/
while (I2caRegs.I2CFFTX.bit.TXFFST!=0 && tx_loop<10000 )
tx_loop++;
if (tx_loop!=10000) {
I2caRegs.I2CSAR.bit.SAR = 16; /* Set slave address*/
I2caRegs.I2CCNT= 1; /* Set data length */
/* mode:1 (1:master 0:slave) Addressing mode:0 (1:10-bit 0:7-bit)
free data mode:0 (1:enbaled 0:disabled) digital loopback mode:0 (1:enabled 0:disabled)
bit count:0 (0:8bit) stop condition:0 (1:enabled 0: disabled)*/
I2caRegs.I2CMDR.all = 26144;
tx_loop= 0;
while (I2caRegs.I2CFFTX.bit.TXFFST==16 && tx_loop<10000)
tx_loop++;
if (tx_loop!=10000) {
I2caRegs.I2CDXR.bit.DATA = (uint8_T)IPDM_Rev_A0_P.Constant1_Value;
IPDM_Rev_A0_B.I2CTransmit = I2caRegs.I2CSTR.all;/* output i2c status */
} else
IPDM_Rev_A0_B.I2CTransmit = I2caRegs.I2CSTR.all | 0x40;/* output transmit data loss status */
} else
IPDM_Rev_A0_B.I2CTransmit = I2caRegs.I2CSTR.all | 0x80;/* output transmit data loss status */
I2caRegs.I2CFFTX.bit.TXFFIENA = 1;/* Enable Tx Fifo interrupt*/
I2caRegs.I2CFFTX.bit.TXFFINTCLR = 1;/* Clear Tx interrupt flag*/
}
/* End of Outputs for S-Function (fcgen): '<S6>/Function-Call Generator' */
}
Simulink HW setup

I am new to the C2000 Series & Simulink, so I hoping this is a simple fix I am missing!
Best Regards,
Neil

