Skip to main content
Visitor
July 16, 2026
Solved

VL53L4CD Interrupt Not Firing After Setting Detection Thresholds

  • July 16, 2026
  • 1 reply
  • 16 views

I have a VL53L4CD that I’m trying to use as a binary signal for detecting whether or not an object is within a specified range. In the default case with no detection thresholds set, GPIO1 is driven low when data is ready as expected, and I can continuously receive data from the sensor by reading when GPIO1 is low and then clearing the interrupt. I set the timing budget to 20 ms, and the intermeasurement time to 50 ms, as was done in the ULD example code (VL53L4CD_ULD_V2.2.3/Examples/Example_6_detection_thresholds.c) . As soon as I add the same call that the example code makes:

 

 VL53L4CD_SetDetectionThresholds((Dev_t)dev_add, 100, 300, 3);

 

At the end of my initialization sequence, GPIO1 no longer pulls down, nor does VL53L4CD_CheckForDataReady(TOF, &ready) signal ready. This is expected behavior outside of 100-300 mm, but I can force read the device regardless of ready status and see measurements within this window that are constantly updating. Is there another step in this process to reconfigure the interrupt/ready signal to use the threshold functionality? Thanks!

Best answer by Bin

Hi:

if you want to run example code, after adding the example function, we must mask all remaining default codes to ensure that only the configuration and result output of the example are run.

int main(void)

{

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_I2C1_Init();

MX_USART2_UART_Init();

/* USER CODE BEGIN 2 */

/* Assign the default address to the sensor */

dev = 0x52;

/* Toggle Xshut pin to reset the sensor */

HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_RESET);

HAL_Delay(5);

HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_SET);

HAL_Delay(5);

/* Print the software version */

status = VL53L4CD_GetSWVersion(&sw_version);

printf("Starting VL53L4CD driver version2.2.3 is %u.%u.%u\n",sw_version.major,sw_version.minor,sw_version.build);

/* run example code */

status = example6();

}

Then focus on the example function, you can set the settings you needed and get the results by interrupt.

WaitForL4CDInterrupt() . At here, just complete the interrupt function, you will get what you want.

 

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

if (GPIO_Pin==GPIO_PIN_4)

{

IntCount++;

}

}

 

uint8_t check_for_gpio_interrupt(void)

{

if(IntCount != 0)

{

IntCount = 0;

return 1;

}

return 0;

}

 

uint8_t WaitForL4CDInterrupt(Dev_t dev)

{

while ( !check_for_gpio_interrupt() );

return(1);

}

Hope the information provided can help you, Thanks~

Best regards,

Bin FAN

1 reply

BinBest answer
ST Technical Moderator
July 17, 2026

Hi:

if you want to run example code, after adding the example function, we must mask all remaining default codes to ensure that only the configuration and result output of the example are run.

int main(void)

{

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_I2C1_Init();

MX_USART2_UART_Init();

/* USER CODE BEGIN 2 */

/* Assign the default address to the sensor */

dev = 0x52;

/* Toggle Xshut pin to reset the sensor */

HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_RESET);

HAL_Delay(5);

HAL_GPIO_WritePin(GPIOB, TOF_C_XSHUT_Pin, GPIO_PIN_SET);

HAL_Delay(5);

/* Print the software version */

status = VL53L4CD_GetSWVersion(&sw_version);

printf("Starting VL53L4CD driver version2.2.3 is %u.%u.%u\n",sw_version.major,sw_version.minor,sw_version.build);

/* run example code */

status = example6();

}

Then focus on the example function, you can set the settings you needed and get the results by interrupt.

WaitForL4CDInterrupt() . At here, just complete the interrupt function, you will get what you want.

 

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

if (GPIO_Pin==GPIO_PIN_4)

{

IntCount++;

}

}

 

uint8_t check_for_gpio_interrupt(void)

{

if(IntCount != 0)

{

IntCount = 0;

return 1;

}

return 0;

}

 

uint8_t WaitForL4CDInterrupt(Dev_t dev)

{

while ( !check_for_gpio_interrupt() );

return(1);

}

Hope the information provided can help you, Thanks~

Best regards,

Bin FAN

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Visitor
July 17, 2026

Thank you! I since solved the issue… after more carefully reading the API comments, I realized that some settings from the init I was using were producing non zero range status returns for all my readings, and that the GPIO only activates for valid ones.