I2C problem in reading VCNL 4040 proximity sensor
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.
