2020-01-10 12:23 PM
Hi,
I got the VCNL4040 Proximity sensor breakout board. I tried this board with Arduino Uno example solution and works very well.
Now, I am trying to read this sensor with an STM32L0 series MCU. I see I am able to write to the sensor by turning ON and OFF the sensor, but I can not read the same or any other registers. The I2C HAL function returns HAL_OK but the value is always 0. Even I checked the signal and tracked all the 0 and 1 bits, they seem to be good based on the datasheet of the sensor.
Attached is the Read & Write protocol of the sensor.
And below is my code to read a register, for example the ID of the sensor (addr = 0x0C) or measurement data (addr = 0x08). The device address is 0x60.
I2C_TX[0] = 0x08; // PS_Data
if (HAL_I2C_Master_Transmit(&hi2c2,0xC0,I2C_TX, 1,2000) != HAL_OK)
Error_Handler();
if (HAL_I2C_Master_Receive(&hi2c2,0xC0,I2C_RX, 2,2000) != HAL_OK)
Error_Handler();
I2C_TX[0] = 0x0C; // Read device info
if (HAL_I2C_Master_Transmit(&hi2c2,0xC0,I2C_TX, 1,2000) != HAL_OK)
Error_Handler();
if (HAL_I2C_Master_Receive(&hi2c2,0xC0,I2C_RX, 2,2000) != HAL_OK)
Error_Handler();
I could read another proximity sensor VL6180X with the same STM MCU. Is it possible that the I2C of STM is mostly compatible with ST's products?
Thanks.
2020-10-20 06:06 AM
Hi,
I have same problem with stm32l476. All i2c read data is zero. Did you resolve this problem?
2024-01-16 02:00 AM
I had the same issue first.
The problem was that I2C read procedure requires a "repeated start" condition instead of "Stop/Start" between Write and Read procedure.
Do not use HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive combination to read a register.
Use HAL_I2C_Mem_Read only which performs a repeated start condition --> VCNL3040 works