Other Parts Discussed in Thread: TMP422, DXP
Dear Support Team,
I try to read the local, remote1 and 2 temperatures via I2C from the TMP422-Q1 register values with a STM32 microcontroller.
Below, my timing configurations can be found.
Below, my Code can be found:
/* SCAN i2C adresses */
HAL_Delay(500);
for( uint8_t i =0; i <255; i++)
{
if(HAL_I2C_IsDeviceReady(&hi2c2, i, 1, 10) == HAL_OK)
{
a[cnt] = i;
cnt ++;
}
}
// Set Conf Reg 2 of external TMP422 sensor
uint8_t CNF_RGY_2_Tx[2];
CNF_RGY_2_Tx[0] = CNF_RGY_2;
CNF_RGY_2_Tx[1] = CNF_RGY_2_SETUP;
if ( HAL_I2C_Master_Transmit(&hi2c2, 0x98, CNF_RGY_2_Tx, 2, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 1;
}
}
// Get Conf Reg 1 of external TMP422 sensor
if ( HAL_I2C_Master_Transmit(&hi2c2, 0x98, &CNF_RGY_1, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 2;
}
if ( HAL_I2C_Master_Receive(&hi2c2, 0x99,(uint8_t *) I2CRx_CNF_RGY_1, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 3;
}
}
}
// Get Conf Reg 2 of external TMP422 sensor
if ( HAL_I2C_Master_Transmit(&hi2c2, 0x98, &CNF_RGY_2, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 4;
}
if ( HAL_I2C_Master_Receive(&hi2c2, 0x99,(uint8_t *) I2CRx_CNF_RGY_2, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 5;
}
}
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
// Get Local Temp
if ( HAL_I2C_Master_Transmit(&hi2c2, 0x98, &PTR_RGY_0, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 6;
}
if ( HAL_I2C_Master_Receive(&hi2c2, 0x99,(uint8_t *) I2CRx_LOC, I2C2_RX_FieldSize, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 7;
}
// Only quick and dirty
if ( I2CRx_LOC[0] >= 0xC0 ) {
TempLoc = -256 + I2CRx_LOC[0] - (double) I2CRx_LOC[1]/256;
}else{
TempLoc = (double) I2CRx_LOC[0] + (double) I2CRx_LOC[1]/256;
}
// Error Analysis
if ( TempLoc == -64 ) {
KS_TLOC = 1;
}
if ( I2CRx_LOC[0] & 0x01 ) {
OK_TLOC = 1;
}
}
}
// Set PTR Register to remote 1 and receive Data
if ( HAL_I2C_Master_Transmit(&hi2c2, 0x98, &PTR_RGY_1, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 8;
}
if ( HAL_I2C_Master_Receive(&hi2c2, 0x99,(uint8_t *) I2CRx_DSP, I2C2_RX_FieldSize, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 9;
}
// Only quick and dirty
if ( I2CRx_DSP[0] >= 0xC0 ) {
Temp = -256 + I2CRx_DSP[0] - (double) I2CRx_DSP[1]/256;
}else{
Temp = (double) I2CRx_DSP[0] + (double) I2CRx_DSP[1]/256;
}
// Error Analysis
if ( TempLoc == -64 ) {
KS_TR1 = 1;
}
if ( I2CRx_DSP[0] & 0x01 ) {
OK_TR1 = 1;
}
}
}
if ( HAL_I2C_Master_Transmit(&hi2c2, 0x98, &PTR_RGY_2, 1, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 10;
}
if ( HAL_I2C_Master_Receive(&hi2c2, 0x99,(uint8_t *) I2CRx_DSP2, I2C2_RX_FieldSize, 100) == HAL_OK )
{
while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{
cnt = 11;
}
// Only quick and dirty
if ( I2CRx_DSP2[0] >= 0xC0 ) {
Temp2 = -256 + I2CRx_DSP2[0] - (double) I2CRx_DSP2[1]/256;
}else{
Temp2 = (double) I2CRx_DSP2[0] + (double) I2CRx_DSP2[1]/256;
}
// Error Analysis
if ( TempLoc == -64 ) {
KS_TR2 = 1;
}
if ( I2CRx_DSP2[0] & 0x01) {
OK_TR2 = 1;
}
}
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
The TMP is connected in such a way, that the adress should be 0x98 / 0x99, depending on the read/write value. These adresses are found by my Code, so that seems to be right.
I manage to read the local and remote 1 temperature values, the remote 2 temperature values are frozen however. The result seems to be an open circuit. If I force a short circuit, the value also changed to the right short circuit value -64.
I just wanted to clarifiy, that there are no timing issues / software mistakes and the error seems to be hardware related.
Thank you and kind regards
Sebastian