2024-08-17 06:39 PM - edited 2024-08-17 07:11 PM
PLEASE IGNORE THIS POST AS I SOLVED IT
I TRIED TO DELETE THIS POST BUT THERE DOES NOT SEEM TO BE A DELETE OPTION?
Hi,
trying to read the temperature of one of the simplest I2C temperature sensor ever... the TMP1075 (datasheet attached).
The bizarre thing is that the room temperature is around 23 degC but...:
1) when I heat it by placing my finger on the sensor the read value actually decrease and viceversa when I cool it
2) the value read is around 33 to 38 (depending on whether I warm it up or cool it) instead of roughly around 22 to 25 deg
The address is correct (I set A0 to 1 on the PCB) and there are no other devices on the bus.
Lost track of how much time I have spent on it so far... Does anybody have any idea what could be the reason?
Thank you as always! 🙂
// I2C address of the TMP1075 sensor (7-bit address)
#define TMP1075_I2C_ADDRESS (0x49 << 1) // 8-bit address for HAL - IC address is 0x49
#define TMP1075_TEMP_REGISTER 0x00 // Temperature register address
// TODO change max delay in I2C and error handling routine
// Read the temperature from the TMP1075
float TMP1075_Read_Temperature(void) {
uint8_t temp_reg_addr = TMP1075_TEMP_REGISTER; // Temperature register address in the temperature IC
uint8_t temp_raw_data[2] = {0}; // Array to hold the raw temperature data (MSB + LSB)
int16_t temp_raw; // 16-bit variable to hold the combined raw temperature value
float temperature; // Variable to hold the calculated temperature
// Send the temperature register address
if (HAL_I2C_Master_Transmit(&hi2c1, TMP1075_I2C_ADDRESS, (uint8_t*) &temp_reg_addr, 1, HAL_MAX_DELAY) != HAL_OK) {
// Transmission error
return -1000.0f; // Error value
}
// Receive 2 bytes of temperature data from the TMP1075
if (HAL_I2C_Master_Receive(&hi2c1, TMP1075_I2C_ADDRESS, temp_raw_data, 2, HAL_MAX_DELAY) != HAL_OK) {
// Reception error
return -1000.0f; // Error value
}
// Combine the MSB and LSB into a 16-bit value
temp_raw = (temp_raw_data[0] << | temp_raw_data[1];
// Right shift the result for 12-bit resolution (TMP1075 in default 12-bit mode)
temp_raw >>= 4;
// Convert the raw temperature to Celsius (TMP1075 is 0.0625°C/LSB)
temperature = temp_raw * 0.0625;
return temperature;
}
2024-08-17 10:29 PM