cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L0X sensor PerformSingleRangingMeasurement ()

NeoMuEoLyeOwoYo
Visitor

Hello. I'm a newbie to stm32 or actually to everything.
I am using VL53L0X sensor and STM32F030C8T6 MCU in stm32idecube.

What I want to do is to get a good reading of the sensor data.

And I want to use a timer interrupt to read the sensor data every certain period and I don't want to read any weird sensor data.


So I used someone's code to read the sensor data using the VL53L0X api to check the sensor data.

But this code doesn't use timer interrupt, so I modified it to set a timer and use VL53L0X_PerformSingleRangingMeasurement function in HAL_TIM_PeriodElapsedCallback function to read sensor data.
This modification didn't work, so I put the VL53L0X_PerformSingleRangingMeasurement function in a while() in the main function, and the sensor data was read in just fine.

Why did I not get the sensor data when I used the function that reads the sensor data from the timer interrupt, but I got the sensor data in while()? Is it possible that this sensor should not be used with a timer?

(For reference, I set the timer interrupt period to 1s).

 

+ I'm getting the sensor data, but I'm having trouble with the value.
It could be a hardware issue or a software issue, but when the sensor data comes in, the value is jumping around too much.
Sometimes I get a value of 20 or 8000 or something like that, otherwise the value is outputting normally.

Please, if anyone is familiar with this sensor, please help me out.

 

I've attached some code below.

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

if (htim->Instance == TIM1)

{

check += 1;

VL53L0X_RangingMeasurementData_t RangingMeasurementData;

dist[1] = VL53L0X_PerformSingleRangingMeasurement(pDev, &RangingMeasurementData);

}

}

 

/* USER CODE END 0 */

 

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

 

/* USER CODE BEGIN 1 */

VL53L0X_Dev_t Laser_1 =

{

.I2cHandle = &hi2c1,

.I2cDevAddr = PROXIMITY_I2C_ADDRESS

};

pLaser_1 = &Laser_1;

/* USER CODE END 1 */

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

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

HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_I2C1_Init();

MX_TIM1_Init();

/* USER CODE BEGIN 2 */

LaserConfig laserConfigs[] = {

{XSHUT0_GPIO_Port, XSHUT0_Pin, pLaser_1, SENSOR_ADDR_1},

};

for (int i = 0; i < sizeof(laserConfigs) / sizeof(LaserConfig); i++)

{

HAL_GPIO_WritePin(laserConfigs[i].GPIOx, laserConfigs[i].GPIO_Pin, GPIO_PIN_SET);

HAL_Delay(20);

VL53L0X_PROXIMITY_Init(laserConfigs[i].p_laser, laserConfigs[i].dev_addr);

}

dist[0] = 0;

 

if (HAL_TIM_Base_Start_IT(&htim1) != HAL_OK)

{

Error_Handler();

}

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

0 REPLIES 0