2024-07-20 02:57 PM
I need help to setup TMP102 alarm function. My board is NUCLEO-F439ZI
Reading the temperature is working fine.
uint8_t TMP102_ADDR = 0x48 << 1;
uint8_t REG_TEMP = 0x00;
uint8_t buf[12];
buf[0] = REG_TEMP;
ret = HAL_I2C_Master_Transmit(&hi2c2, 0x90, buf, 1, 10); // OK
ret = HAL_I2C_Master_Transmit(&hi2c2, 0x90, 0x00, 1, 10); //OK
ret = HAL_I2C_Master_Receive(&hi2c2, 0x90, buf, 2 , 10); //OK
reads the temperature correctly. Buf[0] and buf[1]has correct temperature data.
I am trying to setup the alarm function. Reading/writing the Limit registers are failing.
Datasheet states that Thigh=80C, and Tlow=70C. After Reset.
I am reading the Thigh registers, with the following code:
uint8_t reghi = 0x03;
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, reghi, 1, 10); // fail
is sending 0x00 on reghi. I verified by scope.
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, 0x03, 1, 10); //fail
it is sending 0x00 to configuration register.
The only way to send the right value accomplished by:
Unit8_t reghi = 0x03;
buf[0] = reghigh;
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, buf, 1, 10); OK.
Sending 0x03 to select the Thigh register. Verified by scope.
Now I want to read the value of Thigh.
ret = HAL_I2C_Master_Receive(&hi2c2, TMP102_ADDR, buf, 2 , 100);
The value in buf[0] = 0x00;
The value in buf{1] = 0x00;
I verified it in Debug mode.
The same problem when I write two bytes to Thigh and read it back
It gives 0x00 for both bytes.
If anybody tried to set the alarm successfully in TMp102, please help.
Thanks,
Rasem
Solved! Go to Solution.
2024-07-22 11:06 PM - edited 2024-07-22 11:08 PM
Hi Rasem
try this:
change
temphi[0] = 0x1A;
temphi[1] = 0x00; // set high temp alarm at 26C.
to
temphi[1] = 0x1A;
temphi[0] = 0x00; // set high temp alarm at 26C.
better
uint8_t temphi[3]= {0};
temphi[0] = 0x03; // register
temphi[1] = 0x00; // HiByte
temphi[2] = 0x1A; // LowByte
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, temphi,3, 100);
Hint: An array is always passed as an address.
hth
padawan
2024-07-20 04:42 PM
Yeah, because it want a POINTER, the address of variable, and not the number/constant itself..
uint8_t reghi = 0x03;
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, reghi, 1, 10); // fail
is sending 0x00 on reghi. I verified by scope.
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, 0x03, 1, 10); //fail
it is sending 0x00 to configuration register.
The only way to send the right value accomplished by:
uint8_t reghi = 0x03;
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, (void *)®hi, 1, 10); // pass via pointer
2024-07-21 12:06 AM
Hi Tesla DeLorean,
Thank you very much for your quick reply. It was great. I am able to read the High Temperature setting of
80C correctly.
I still need your help setting my own limits:
The following did not work.
uint8_t reghi = 0x03;
uint8_t temphi[2];
uint8_t lowlimit [2];
temphi[0] = 0x1A;
temphi[1] = 0x00; // set high temp alarm at 26C.
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, (void *)®hi, 1, 10); //OK
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, (void*)&temphi,2, 100);
ret = HAL_I2C_Master_Receive(&hi2c2, TMP102_ADDR, lowlimit, 2 , 100);
// reads lowlimit[0]=0x00, lowlimit[1]=0x00
Coffee on it's way.Thanks.
Rasem
2024-07-22 11:06 PM - edited 2024-07-22 11:08 PM
Hi Rasem
try this:
change
temphi[0] = 0x1A;
temphi[1] = 0x00; // set high temp alarm at 26C.
to
temphi[1] = 0x1A;
temphi[0] = 0x00; // set high temp alarm at 26C.
better
uint8_t temphi[3]= {0};
temphi[0] = 0x03; // register
temphi[1] = 0x00; // HiByte
temphi[2] = 0x1A; // LowByte
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, temphi,3, 100);
Hint: An array is always passed as an address.
hth
padawan
2024-07-29 10:14 PM
Hi Padawan.
Great solution. It is working now after sending 3 bytes togther.
Thank you very much.
Rasem