cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] - Simple temperature sensor I2C reading gives bizarre incorrect reading

Ricko
Senior II

 

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;
}

 

 

 

 

4 REPLIES 4
STOne-32
ST Employee

Hi @Ricko ,

Thank you for writing back and happy that you solved the case !

Ciao

STOne-32

Hi @STOne-32

there does not appear to be an option to delete the post (see screenshots below of the only two menus available at least on my browser)? Surely that cannot be...? How does someone delete a post?

Thank you

Ricko_0-1723981453563.png

 

Ricko_1-1723981479358.png

 

 

Right, because deleting content damages the forum. Explain what the issue was and how you solved it, as that might provide some value to visitors in the future.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ricko
Senior II

Thank you @Tesla DeLorean 

I appreciate what you are saying but I don't think deleting a post you made 10 minutes earlier would damage the forum.

Most likely nobody even saw it and if you noticed it was a silly mistake you made and just found out soon after the post, I think it is more respectful to other members - especially those who try to help (like you) - to just delete it to avoid wasting their time.

Perhaps allowing the poster to delete a post either until the first reply is posted or perhaps in the first 20 minutes or so might be a good idea (like Amazon allows you 20-30 minutes to delete an order and the card is not charged). Just a thought though...

 

In terms of how I solved it, it was actually working correctly all along... it turned out that there was a trace nearby that was warming up the IC but not enough to detect it when touching it. The finger temperature was a couple of degrees lower than the IC (I assumed it would be warmer) so that's why when touching the IC the readout was lowering instead of increasing.

 

Thank you as always!