cancel
Showing results for 
Search instead for 
Did you mean: 

LoRaWAN-End-Node + VL53L4CD, Sleep issue

AElgh
Associate III

Hello, I'm using the LoRaWAN-End-Node example on an STM32WL55JC MCU to drive the VL53L4CD sensor.  

I would like to use the interrupt pin to get the data from the sensor.

what is happening is that once __WFI() in the getting data subroutine is executed (code below), the LoRaWAN cycle seems to be broken.

How can i embed the "Sleep until an interrupt" in the LoRaWAN cycle?

Thank you...

void VL53_data_interrupt(cData_t *sensordata)
{
	//    static uint8_t i = 0;
 
	    while (meas_count < NUM_MEASUREMENTS)
	    {
	        __WFI();    // Wait for interrupt
 
	        if (IntCount != 0)
	        {
	            IntCount = 0;
 
	            /* (Mandatory) Clear HW interrupt to restart measurements */
	            VL53L4CD_ClearInterrupt(sensordata->Vl53_Dev);
 
	            /* Read measured distance. RangeStatus = 0 means valid data */
	            VL53L4CD_GetResult(sensordata->Vl53_Dev, &(sensordata->VL53_Res));
 
	            if (sensordata->VL53_Res.range_status == 0)
	            {
	                Arr_dist_mm[meas_count] = sensordata->VL53_Res.distance_mm;
 
	//                printf("Distance = %3u mm\n", results.distance_mm);
 
	                Acc_Dist += sensordata->VL53_Res.distance_mm;
 
	                meas_count++;
	            }
	        }
	    }
 
	    uint32_t Av_Distance = Acc_Dist / NUM_MEASUREMENTS;
 
	    printf("Average distance = %5lu mm\n", Av_Distance);
 
	    meas_count = 0;
 
	    Acc_Dist   = 0;
}

2 REPLIES 2

You're trying to do this in an INTERRUPT ??

Need to come up with a method that does this statefully

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The Interrupt is working fine until the Stop-Mode is enabled then a strange behavior starts to happen:

  • sensor data is captured only once :

As the XShut(Interrupt-Pin) gets triggered when the MCU 1st stars.

  • the data is wrong.

I can go with the busy-wait solution but I'm trying to optimize the power as much as possible.