Associate II
January 5, 2023
Solved
VL53L1X problem with write value to register
- January 5, 2023
- 4 replies
- 2111 views
Hello, I solve a problem with writing the value to the register of sensor VL53L1X. It is the main purpose, why the sensor doesn´t read distance because the init state is invalid.
For example, I tried to write the value 0x2 to the register 0x30 on the Arduino board and then on the BluePill board with chip STM32f103C8T6. On the Arduino, it worked, but on the STM didnť work.
I´m adding PrintScreens from the oscilloscope with the same message in Arduino and in STM for comparison. The messages are different in length and count of peaks. It looks like, then STM has an incorrect SCL.

I´m also adding the STM code using vl53l1_platform.c
// STM write and read byte
status += VL53L1_WrByte(dev, 0x30, 0x2);
status += VL53L1_RdByte(dev, 0x30, &byteData);
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data) {
StatusErr = 0;
int32_t status_int;
_I2CBuffer[0] = (uint8_t)(index >> 8);
_I2CBuffer[1] = (uint8_t)(index & 0xFF);
_I2CBuffer[2] = (uint8_t)data;
status_int = _I2CWrite(dev, _I2CBuffer, 3);
if (status_int != 0) {
//comm error
//return 255;
StatusErr = 13;
}
return StatusErr;
}
int _I2CWrite(uint16_t Dev, uint8_t *pdata, uint32_t count) {
int status;
int i2c_time_out = I2C_TIME_OUT_BASE+ count* I2C_TIME_OUT_BYTE;
status = HAL_I2C_Master_Transmit(&hi2c2,(Dev<<1),pdata, count, 1000); //(Dev<<1)
// if status 1 - error
if (status) {
return 255;
}
// if Ok return 0
return status;
}Please, has anyone dealt with the same problem?
