Tool/software: Code Composer Studio
Hello, I am trying to create device drivers for the INA226. When I try to send or receive data over the I2C interface, my code gets stuck in an infinite loop. I am using a Hercules Launchpad TMS570LC43x microcontroller. It does not seem like the data is transferring. Below is the code.
#include "HL_sys_common.h"
/* USER CODE BEGIN (1) */
/* Include FreeRTOS scheduler files */
#include "FreeRTOS.h"
#include "os_task.h"
/* Include HET header file - types, definitions and function declarations for system driver */
#include "HL_het.h"
#include "HL_gio.h"
#include "HL_i2c.h"
void main(void)
{
/* USER CODE BEGIN (3) */
//Set slave address
uint32 SLAVE_ADDR = 1000000;
uint32 slave_add = SLAVE_ADDR << 1;
slave_add |= 1;
//Following Halcogen example code
i2cInit();
i2cSetSlaveAdd(i2cREG1, slave_add);
i2cSetDirection(i2cREG1,I2C_RECEIVER);
i2cSetMode(i2cREG1,I2C_MASTER);
i2cSetStop(i2cREG1);
i2cClearSCD(i2cREG1);
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1,slave_add);
uint8 test1 = i2cReceiveByte(i2cREG1); // Code gets stuck here
while(i2cIsBusBusy(i2cREG1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
return;
/* USER CODE END */
}
The code gets stuck in the i2cReceiveByte() function. Below is the while loop where it is getting stuck.
uint8 i2cReceiveByte(i2cBASE_t *i2c)
{
/*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found - Hardware Status check for execution sequence" */
while ((i2c->STR & (uint32)I2C_RX_INT) == 0U) //code gets stuck here
{
} /* Wait */
/* USER CODE BEGIN (25) */
/* USER CODE END */ return ((uint8)i2c->DRR);
}
Does anyone know how I can stop getting stuck in this loop?