Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 220827

Forum Post: TMS570LS3137: Temperature Sensor(tmp101na/3k)

$
0
0
Part Number: TMS570LS3137 Other Parts Discussed in Thread: HALCOGEN , CODECOMPOSER , TMP101 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 >= 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 */

Viewing all articles
Browse latest Browse all 220827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>