From 505ac4e24cf4e7ea85cc9072b470eb65cbd6a1b0 Mon Sep 17 00:00:00 2001 From: whowechina Date: Sun, 19 Nov 2023 16:38:54 +0800 Subject: [PATCH] Fix VL53L0X timeout issue --- firmware/src/vl53l0x.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/firmware/src/vl53l0x.c b/firmware/src/vl53l0x.c index 757fc89..c0932e3 100644 --- a/firmware/src/vl53l0x.c +++ b/firmware/src/vl53l0x.c @@ -15,7 +15,7 @@ #define VL53L0X_DEF_ADDR 0x29 -#define IO_TIMEOUT_US 10000 +#define IO_TIMEOUT_US 25000 // Decode VCSEL (vertical cavity surface emitting laser) pulse period in PCLKs #define decodeVcselPeriod(reg_val) (((reg_val) + 1) << 1) @@ -773,8 +773,11 @@ void vl53l0x_stop_continuous() // single-shot range measurement) uint16_t readRangeContinuousMillimeters() { - if ((read_reg(RESULT_INTERRUPT_STATUS) & 0x07) == 0) { - return 65535; + uint32_t start = time_us_32(); + while ((read_reg(RESULT_INTERRUPT_STATUS) & 0x07) == 0) { + if (time_us_32() - start > IO_TIMEOUT_US) { + return 65535; + } } // assumptions: Linearity Corrective Gain is 1000 (default);