Other Parts Discussed in Thread: HALCOGEN, CODECOMPOSER, TMP101, ADS1115, TMS570LS1224,
Tool/software:
can anyone please help me i am trying to read the temperature from tmp101na my code is stuck in readTemperature function in first i2c send why it stucking i am using halcogen and codecomposer to write the code i am providing the code please review and tell me the issue
/* USER CODE BEGIN (0) */
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "i2c.h"
#include "sci.h"
#include "sys_core.h"
#include "stdio.h"
uint16_t delay=0;
/* 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) */
// Function to read temperature data from TMP101
uint16_t readTemperature(void)
{
uint8_t tempData[2];
uint16_t temperature = 0;
uint8_t configData[2];
configData[0] = 0x01; //configuration register
configData[1] = 0x60; // Configuration byte (R1=1, R0=1 for 12-bit resolution)
// Write configuration to TMP101
i2cSetSlaveAdd(i2cREG1, 0x48);
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cSetCount(i2cREG1, 2);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1); // Send I2C start condition
i2cSend(i2cREG1,3,configData);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
for(delay=0;delay<1000;delay++);
// Start communication to TMP101 to select temperature register
while(i2cIsMasterReady(i2cREG1) != true);
i2cSetSlaveAdd(i2cREG1, 0x48);
i2cSetDirection(i2cREG1,I2C_TRANSMITTER );
i2cSetCount(i2cREG1, 1);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1); // Send I2C start condition
i2cSendByte(i2cREG1,0x00); // Set pointer to the temperature register
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
for(delay=0;delay<1000;delay++);
while(i2cIsBusBusy(i2cREG1) != true);
i2cSetSlaveAdd(i2cREG1, 0x48);
i2cSetDirection(i2cREG1, I2C_RECEIVER);
i2cSetCount(i2cREG1, 2);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1); // Send I2C start condition
i2cReceive(i2cREG1,2,tempData);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
for(delay=0;delay<1000;delay++);
// Combine the two bytes of temperature data
temperature = (tempData[0] << 8) | tempData[1];
temperature >>= 4; // Right shift to adjust for 12-bit data format
return temperature;
}
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
// Initialize system and I2C communication
i2cInit();
sciInit();
while(1)
{
// Read and display the temperature data
uint16_t temperature = readTemperature();
uint8_t tempBytes[2];
// Break the 16-bit temperature value into two 8-bit values
tempBytes[0] = (uint8_t)(temperature >> 8); // Higher byte
tempBytes[1] = (uint8_t)(temperature & 0xFF); // Lower byte
// Send the two bytes via SCI
sciSend(scilinREG, sizeof(tempBytes), tempBytes);
// Add a delay if necessary
}
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
/* USER CODE END */