I am trying to set up my STM32 microcontroller with HAL libraries to read from a ADT7420 temperature sensor using i2c. However I am unable to read the correct value from the sensor as I run my code.
Here is how I have done it so far using HAL libraries:
uint8_t I2C_ADDR = 0x48;
uint8_t TEMP_CONFIG = 0x03;
uint8_t data[2];
HAL_I2C_Master_Transmit(&hi2c1, I2C_ADDR, &TEMP_CONFIG , 1, 10000);
HAL_I2C_Master_Receive(&hi2c1, I2C_ADDR, data, 2, 10000);
uint16_t temp_raw = (uint16_t)((data[0]<<8) | data[1]);
int temp_value = calc_celcius(temp_raw); //TODO: convert to Celsius
Using this code, the temperature stays at zero indicating that something is not working correctly. Am I missing some config settings for the i2c setup in order to read the temperature value? Thanks.