2024-01-09 01:52 AM - edited 2024-01-09 02:38 AM
Hello !
I'm working on the VL53L5CX sensor with a Nucleo L432KC.
Using the ST example, and after succeeded the initialization of the VL53L5CX, the sensor's data are never ready. In the following function, the p_dev->temp_buffer[1:4] are all equals to 0 :
uint8_t vl53l5cx_check_data_ready(
VL53L5CX_Configuration *p_dev,
uint8_t *p_isReady)
{
uint8_t status = VL53L5CX_STATUS_OK;
status |= RdMulti(&(p_dev->platform), 0x0, p_dev->temp_buffer, 4);
for (uint8_t i = 0; i < 4; i++)
printf("0x%02X", p_dev->temp_buffer[i]);
printf("\n");
if((p_dev->temp_buffer[0] != p_dev->streamcount)
&& (p_dev->temp_buffer[0] != (uint8_t)255)
&& (p_dev->temp_buffer[1] == (uint8_t)0x5)
&& ((p_dev->temp_buffer[2] & (uint8_t)0x5) == (uint8_t)0x5)
&& ((p_dev->temp_buffer[3] & (uint8_t)0x10) ==(uint8_t)0x10)
)
{
*p_isReady = (uint8_t)1;
p_dev->streamcount = p_dev->temp_buffer[0];
}
else
{
if ((p_dev->temp_buffer[3] & (uint8_t)0x80) != (uint8_t)0)
{
status |= p_dev->temp_buffer[2]; /* Return GO2 error status */
}
*p_isReady = 0;
}
return status;
}
So do you know why this buffer is always equal to 0, and make the sensor never ready ?
Thank you !
Clément Poisson.
Solved! Go to Solution.
2024-01-19 06:13 AM
The problem was that the WrMulti function was coded with a loop. For the one how would have the same problem, there is my platform (and please put the max timout delay to load the firmware) :
uint8_t WrMulti(
VL53L5CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size)
{
uint8_t status = 255;
status = HAL_I2C_Mem_Write(I2C, p_platform->address, RegisterAdress, 2, p_values, size, 0xFFFFFFFF);
return status;
}
uint8_t RdMulti(
VL53L5CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size)
{
uint8_t status = 255;
status = HAL_I2C_Mem_Read(I2C, p_platform->address, RegisterAdress, 2, p_values, size, I2CTIMEOUT);
return status;
}
2024-01-18 02:34 AM
Hello !
I am still looking for a solution to this problem. I tried to implement the code on another VL53L5CX-SATEL, but the problem stay the same.
Do you have a solution ?
Thank you !
Clement.
2024-01-18 07:40 AM
if the sensor is ranging you can see it. Point a web-cam at it, or use a cell-phone, but not an IPhone. The IR sensors on that phone are too good and eliminate the light.
But I'm guessing you did not get the chip initialized. Did you carefully check the status on each of the function calls when you initialized the chip? I'm guessing one of them is failing.
Or you could have the chip still in reset. Check to see that the LPn pin is high. Without that the sensor will not work.
- john
2024-01-19 12:42 AM - edited 2024-01-19 12:43 AM
Thank you for your answer !
I pointed a camera on the sensor but I am not sure to see or not the IR laser.
I also already checked the status, and the initialization seems correct. This is my code and the Serial Monitor :
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
MX_USART2_UART_Init();
HAL_Delay(2000);
printf("Hello World!\r\n");
/*********************************/
/* VL53L5CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L5CX_Configuration Dev; /* Sensor configuration */
VL53L5CX_ResultsData Results; /* Results data from VL53L5CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L5CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l5cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L5CX sensor connected */
status = vl53l5cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L5CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L5CX sensor */
status = vl53l5cx_init(&Dev);
if(status)
{
printf("VL53L5CX ULD Loading failed\n");
return status;
}
printf("VL53L5CX ULD ready ! (Version : %s)\n",
VL53L5CX_API_REVISION);
status = vl53l5cx_set_ranging_frequency_hz(&Dev, 50);
uint8_t power_mode = 0;
status = vl53l5cx_get_power_mode(&Dev, &power_mode);
printf("Power mode = %d\n", power_mode);
uint32_t time_ms = 0;
status = vl53l5cx_get_integration_time_ms(&Dev, &time_ms);
printf("Integration time : %ld ms\n", time_ms);
uint8_t resolution = 0;
status = vl53l5cx_set_resolution(&Dev, VL53L5CX_RESOLUTION_4X4);
status = vl53l5cx_get_resolution(&Dev, &resolution);
printf("Resolution : %d\n", resolution);
status = vl53l5cx_start_ranging(&Dev);
if(status)
{
printf("Start Ranging Failed\n");
return status;
}
/*********************************/
/* Ranging loop */
/*********************************/
loop = 0;
while(1)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A3
* (GPIO 1) when a new measurement is ready */
status = vl53l5cx_check_data_ready(&Dev, &isReady);
printf("Status data_ready: %d\n", status);
if(isReady)
{
vl53l5cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L5CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L5CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
else
{
status = vl53l5cx_is_alive(&Dev, isAlive);
if (status)
{
printf("VL53L5CX died ...\n");
return status;
}
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(5);
}
status = vl53l5cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}
Hello World!
VL53L5CX ULD ready ! (Version : VL53L5CX_1.3.10)
Power mode = 1
Integration time : 10 ms
Resolution : 16
Status data_ready: 0
Status data_ready: 0
Status data_ready: 0
(etc...)
So I am pretty sure that the init is okay. I also checked tha ne LPn pin is high.
Do you have an idea of the origine of the problem ?
Thank you for all,
Clément.
2024-01-19 06:13 AM
The problem was that the WrMulti function was coded with a loop. For the one how would have the same problem, there is my platform (and please put the max timout delay to load the firmware) :
uint8_t WrMulti(
VL53L5CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size)
{
uint8_t status = 255;
status = HAL_I2C_Mem_Write(I2C, p_platform->address, RegisterAdress, 2, p_values, size, 0xFFFFFFFF);
return status;
}
uint8_t RdMulti(
VL53L5CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size)
{
uint8_t status = 255;
status = HAL_I2C_Mem_Read(I2C, p_platform->address, RegisterAdress, 2, p_values, size, I2CTIMEOUT);
return status;
}