VL53L1x communication with STM8S105 MCU
Dear all,
I have just put the X-NUCLEO-53L1A1 kit into operation together with Arduino UNO and everything works perfectly, using the "X_NUCLEO_53L1A1_HelloWorld" application package.
Then I mounted one of the same two VL53L1X-SATEL sensors by interfacing it with the STM8S MCU, using the "VL53L1X ULD API" application package, but here I still have a basic problem that I can't explain.
Before sending the FW used, based on the following flow:
I would like to briefly describe the defect found in the "VL53L1X_GetInterruptPolarity" function, called within "VL53L1X_CheckForDataReady", in turn called within "VL53L1X_SensorInit".
The problem is that in the following function:
VL53L1X_ERROR VL53L1X_CheckForDataReady (uint16_t dev, uint8_t * isDataReady)
{
uint8_t Temp;
uint8_t IntPol;
VL53L1X_ERROR status = 0;
status | = VL53L1X_GetInterruptPolarity (dev, & IntPol);
status | = VL53L1_RdByte (dev, GPIO__TIO_HV_STATUS, & Temp);
/ * Read in the register to check if a new value is available * /
if (status == 0) {
if ((Temp & 1) == IntPol)
* isDataReady = 1;
else
* isDataReady = 0;
}
return status;
}
equality (Temp & 1) == IntPol IS NEVER VERIFIED !!!
Just to remember:
L53L1X_ERROR VL53L1X_GetInterruptPolarity(uint16_t dev, uint8_t *pInterruptPolarity)
{
uint8_t Temp;
VL53L1X_ERROR status = 0;
status |= VL53L1_RdByte(dev, GPIO_HV_MUX__CTRL, &Temp);
Temp = Temp & 0x10;
*pInterruptPolarity = !(Temp>>4);
return status;
}
Comparing with the oscilloscope the I2C bytes exchanged in the working case of Arduino UNO and in the non-working case STM8S105, we have the following:
- Arduino UNO "VL53L1X_GetInterruptPolarity":
- STM8S105 "VL53L1X_GetInterruptPolarity":
Comparing to Arduino UNO we expect to read the byte 0x01 from the register GPIO_HV_MUX__CTRL, but on STM8S105 we always read 0x11!!!
Due to this problem we have always been stuck inside the function without being able to receive any distance measurement data since dataReady == 0 ALWAYS TRUE !!! (data NEVER READY)
Please, anyone have experience with VL53L1X ULD implemented on STM8S MCU?
I can provide other details if necessary.
I would be very grateful.
Thanks.
CCenci
PS. Just to remember from ULD on STM8S105:
VL53L1X_ERROR VL53L1X_SensorInit(uint16_t dev)
{
VL53L1X_ERROR status = 0;
uint8_t Addr = 0x00, tmp;
for (Addr = 0x2D; Addr <= 0x87; Addr++)
status |= VL53L1_WrByte(dev, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
status |= VL53L1X_StartRanging(dev);
tmp = 0;
while(tmp==0)
status |= VL53L1X_CheckForDataReady(dev, &tmp);
status |= VL53L1X_ClearInterrupt(dev);
status |= VL53L1X_StopRanging(dev);
status |= VL53L1_WrByte(dev, (uint16_t)VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
status |= VL53L1_WrByte(dev, (uint16_t)0x0B, 0); /* start VHV from the previous temperature */
return status;
}
