cancel
Showing results for 
Search instead for 
Did you mean: 

I2C problem in reading VCNL 4040 proximity sensor

ashah.16
Associate II

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.

This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Jlee.6
Associate

Hi,

I have same problem with stm32l476. All i2c read data is zero. Did you resolve this problem?​

SEise
Associate II

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