Part Number: TM4C1294NCPDT
Hello everyone,
I have a problem regarding the configuration of TM4C1294 as a slave in I2C communication. In my project, it is communicating with other MCU (same type) which is master. I would like to configure this one as a slave which rises interrupt when a specific amount of bytes is received to the FIFO. For example, I first tried as with two, but I cannot get it to read data from FIFO. When checked in the debugger, the value is 0 when read with "nonblocking" or code blocks if it is read with blocking function. I suppose I did not configure MCU peripheral well. When I use single byte receive it works good, but I would rather use FIFO since messages transmitted between MCU-s will be of 2-3 bytes length. Here is my code for the slave MCU:
void I2C_Configuration()
{
SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C2);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C2));
GPIOPinConfigure(GPIO_PN4_I2C2SDA);
GPIOPinConfigure(GPIO_PN5_I2C2SCL);
GPIOPinTypeI2CSCL(GPIO_PORTN_BASE, GPIO_PIN_5);
GPIOPinTypeI2C(GPIO_PORTN_BASE, GPIO_PIN_4);
I2CSlaveInit(I2C2_BASE, SLAVE_ADDRESS);
I2CSlaveIntEnable(I2C2_BASE);
I2CRxFIFOConfigSet(I2C2_BASE, I2C_FIFO_CFG_RX_SLAVE | I2C_FIFO_CFG_RX_TRIG_2);
I2CRxFIFOFlush(I2C2_BASE);
I2CSlaveIntEnableEx(I2C2_BASE, (I2C_SLAVE_INT_RX_FIFO_REQ));
IntEnable(INT_I2C2);
I2CIntRegister(I2C2_BASE, I2C2SlaveIntHandler);
I2CSlaveEnable(I2C2_BASE);
}
void I2C2SlaveIntHandler(void)
{
uint32_t ui32I2CMasterInterruptStatus;
ui32I2CMasterInterruptStatus = I2CSlaveIntStatusEx(I2C2_BASE, true);
uint32_t i =0;
for(i=0; i<2; i++)
{
I2CFIFODataGetNonBlocking(I2C2_BASE, &dat[i]);
}
I2CRxFIFOFlush(I2C2_BASE);
I2CSlaveIntClearEx(I2C0_BASE, I2C_SLAVE_INT_RX_FIFO_REQ);
}
And here is master MCU configuration and write functions
void I2C_Configuration()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
GPIOPinConfigure(GPIO_PN4_I2C2SDA);
GPIOPinConfigure(GPIO_PN5_I2C2SCL);
GPIOPinTypeI2CSCL(GPIO_PORTN_BASE, GPIO_PIN_5);
GPIOPinTypeI2C(GPIO_PORTN_BASE, GPIO_PIN_4);
I2CMasterInitExpClk(I2C2_BASE, g_ui32SysClock, false);
I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADR, false);
}
uint8_t I2CWriteData(uint8_t slave_addr, uint8_t dev_reg, uint8_t *dat, uint8_t count)
{
while ( I2CMasterBusy(I2C2_BASE) );
I2CMasterSlaveAddrSet(I2C2_BASE, slave_addr, false);
uint8_t i=0;
while ( I2CMasterBusy(I2C2_BASE) );
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_START);
for(i=0; i<count; i++)
{
while ( I2CMasterBusy(I2C2_BASE) );
I2CMasterDataPut(I2C2_BASE, dat[i]);
if(i!=(count-1))
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
else
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_STOP);
}
while ( I2CMasterBusy(I2C2_BASE) );
return 1;
}


