Other Parts Discussed in Thread: TMS570LS3137
Tool/software: Code Composer Studio
I want to interface AT24C256 with Hercules TMS570LS31x/21x Development Kit, following code was not working:
#include "het.h"
#include "gio.h"
#include "rti.h"
#include "i2c.h"
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
#define Slave_Address 0xA0 // 1 0 1 0 0 A1 A0 R/W
uint8_t TX_Data[4] = {0x00, 0x00, 0xAA, 0x55}; // first two bytes are word address then 2 bytes are data
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
i2cInit();
i2cSetSlaveAdd(i2cREG1, Slave_Address);
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cSetCount(i2cREG1, 4);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSend(i2cREG1, 4, TX_Data);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
while(1);
/* USER CODE END */
}
The controller is waiting in the i2cSend() function as follows:
void i2cSend(i2cBASE_t *i2c, uint32 length, uint8 * data)
{
/* USER CODE BEGIN (17) */
/* USER CODE END */
if ((g_i2cTransfer_t.mode & (uint32)I2C_TX_INT) != 0U)
{
/* Interrupt mode */
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
g_i2cTransfer_t.data = data;
/* start transmit by sending first byte */
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
i2c->DXR = (uint32)(*g_i2cTransfer_t.data);
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
/*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
g_i2cTransfer_t.data++;
/* Length -1 since one data is written already */
g_i2cTransfer_t.length = (length - 1U);
/* Enable Transmit Interrupt */
i2c->IMR |= (uint32)I2C_TX_INT;
}
else
{
/* send the data */
while (length > 0U)
{
/*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found - Hardware Status check for execution sequence" */
while ((i2c->STR & (uint32)I2C_TX_INT) == 0U) < < <- - - - controller is waiting here
{
} /* Wait */
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
i2c->DXR = (uint32)(*data);
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
/*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
data++;
length--;
}
}
/* USER CODE BEGIN (18) */
/* USER CODE END */
}