cancel
Showing results for 
Search instead for 
Did you mean: 

Why HAL_I2C_Mem_Read returns only 0?

ATavo.1
Associate III

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]​ 

1 ACCEPTED SOLUTION

Accepted Solutions

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?

View solution in original post

12 REPLIES 12

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

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

Slave address, and register address look correct, is it timing out, or not responding at all?

Have you scoped the pins?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ATavo.1
Associate III

I used the debug and I didn't get any errors and I only get zero.0693W00000LyDsPQAV.jpgI checked the pull-ups and the slave address is 0x40.

It seems okay.

The data sheet for the sensor is attached below.

The array defaults would be zero.

Any other registers in the part readable?

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

sadly no.

MFran.4
Senior

Scoping the pins is a good idea.

What does HAL_I2C_MemRead return as status? (stat = HAL_I2C_Memread(...) )

ATavo.1
Associate III

I

It show HAL_ERROR

It works fine. No timing out or any error in debug but the return of the HAL_I2C_Mem_Read is HAL_Error.