2022-04-18 02:57 AM
Hi,
I am using stm32f1 and HUT21D sensor (Temperature and humidity sensor). The sensor use i2c for communication.
I am using IAR and cubeMX.
For cube: I used default setting for i2c.
For IAR: I shared the main.c below.
Can anyone help on why only get 0.
#I2C #[STM32 MCUs]
Solved! Go to Solution.
2022-04-20 02:32 AM
It could be the wires but 10cm is still a human distance. Did you measure with an oscilloscope SDA and SCL? Are the waveforms clean?
2022-04-18 04:39 AM
Does the function return an error or success code?
If HTU21D_RX_DATA is filled with a different data pattern, does it return that?
That would be indicative that the device is not responding.
Check wiring, pins used, pull-ups, and slave address
2022-04-18 04:47 AM
Slave address, and register address look correct, is it timing out, or not responding at all?
Have you scoped the pins?
2022-04-18 05:06 AM
2022-04-18 06:18 AM
The array defaults would be zero.
Any other registers in the part readable?
2022-04-19 10:58 PM
sadly no.
2022-04-20 12:15 AM
Scoping the pins is a good idea.
What does HAL_I2C_MemRead return as status? (stat = HAL_I2C_Memread(...) )
2022-04-20 01:10 AM
I
2022-04-20 01:23 AM
It show HAL_ERROR
2022-04-20 01:27 AM
It works fine. No timing out or any error in debug but the return of the HAL_I2C_Mem_Read is HAL_Error.