Sample application using interrupts, and range_continuous_interrupts mode, to receive range data from the on-board and satellite sensors. Results are displayed on the on-board, 4 digit display and on the COM port.

Dependencies:   mbed X_NUCLEO_53L0A1

Fork of Display_53L0A1_Interrupts by ST

* NOTE : Hard-links U11 and U18, on the underside of the X-NUCELO-53L0A1 expansion board, must be made/ON to allow interrupts to be received from the satellite boards, on INT_L and INT_R, or U10 and U15 to receive interrupts from the alternate locations. *

Committer:
johnAlexander
Date:
Tue Jun 13 15:31:26 2017 +0000
Revision:
1:c1c10e0c32b2
Parent:
0:cd8e818d4288
Child:
2:bdf097d93eca
Refactor, to remove unused, or legacy code.; Update comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 1:c1c10e0c32b2 1 /*
johnAlexander 1:c1c10e0c32b2 2 * This VL53L0X Expansion board test application performs range measurements
johnAlexander 1:c1c10e0c32b2 3 * using the onboard embedded centre sensor, in singleshot, polling mode.
johnAlexander 1:c1c10e0c32b2 4 * Measured ranges are displayed on the on-board 4-digit display.
johnAlexander 1:c1c10e0c32b2 5 *
johnAlexander 1:c1c10e0c32b2 6 * The User Blue button stops the current measurement and entire program,
johnAlexander 1:c1c10e0c32b2 7 * releasing all resources.
johnAlexander 1:c1c10e0c32b2 8 *
johnAlexander 1:c1c10e0c32b2 9 * The Reset button can be used to restart the program.
johnAlexander 1:c1c10e0c32b2 10 */
johnAlexander 1:c1c10e0c32b2 11
johnAlexander 1:c1c10e0c32b2 12 #include <string.h>
johnAlexander 1:c1c10e0c32b2 13 #include <stdio.h>
johnAlexander 1:c1c10e0c32b2 14
johnAlexander 0:cd8e818d4288 15 #include "mbed.h"
johnAlexander 0:cd8e818d4288 16 #include "x_nucleo_53l0a1.h"
johnAlexander 0:cd8e818d4288 17
johnAlexander 0:cd8e818d4288 18 #define VL53L0_I2C_SDA D14
johnAlexander 0:cd8e818d4288 19 #define VL53L0_I2C_SCL D15
johnAlexander 0:cd8e818d4288 20
johnAlexander 1:c1c10e0c32b2 21 static X_NUCLEO_53L0A1 *board = NULL;
johnAlexander 0:cd8e818d4288 22 VL53L0X_RangingMeasurementData_t data_sensor_centre;
johnAlexander 0:cd8e818d4288 23 OperatingMode operating_mode;
johnAlexander 0:cd8e818d4288 24
johnAlexander 0:cd8e818d4288 25 /* flags that handle interrupt request */
johnAlexander 1:c1c10e0c32b2 26 bool int_stop_measure = false;
johnAlexander 0:cd8e818d4288 27
johnAlexander 0:cd8e818d4288 28 /* ISR callback function of the user blue button to stop program */
johnAlexander 0:cd8e818d4288 29 void StopMeasureIRQ(void)
johnAlexander 0:cd8e818d4288 30 {
johnAlexander 1:c1c10e0c32b2 31 int_stop_measure = true;
johnAlexander 0:cd8e818d4288 32 }
johnAlexander 0:cd8e818d4288 33
johnAlexander 0:cd8e818d4288 34 /* On board 4 digit local display refresh */
johnAlexander 1:c1c10e0c32b2 35 void DisplayRefresh(VL53L0X_RangingMeasurementData_t sensor_range_data)
johnAlexander 0:cd8e818d4288 36 {
johnAlexander 0:cd8e818d4288 37 char str[5];
johnAlexander 0:cd8e818d4288 38
johnAlexander 1:c1c10e0c32b2 39 if (sensor_range_data.RangeStatus == 0) // we have a valid range.
johnAlexander 0:cd8e818d4288 40 {
johnAlexander 1:c1c10e0c32b2 41 sprintf(str,"%d", sensor_range_data.RangeMilliMeter);
johnAlexander 1:c1c10e0c32b2 42 }
johnAlexander 1:c1c10e0c32b2 43 else
johnAlexander 1:c1c10e0c32b2 44 {
johnAlexander 1:c1c10e0c32b2 45 sprintf(str,"%s","----");
johnAlexander 0:cd8e818d4288 46 }
johnAlexander 0:cd8e818d4288 47
johnAlexander 0:cd8e818d4288 48 board->display->DisplayString(str);
johnAlexander 0:cd8e818d4288 49 }
johnAlexander 0:cd8e818d4288 50
johnAlexander 1:c1c10e0c32b2 51 /*=================================== Main ==================================
johnAlexander 1:c1c10e0c32b2 52 Press the blue user button to stop measurements in progress
johnAlexander 1:c1c10e0c32b2 53 =============================================================================*/
johnAlexander 1:c1c10e0c32b2 54 int main()
johnAlexander 1:c1c10e0c32b2 55 {
johnAlexander 1:c1c10e0c32b2 56 #if USER_BUTTON == PC_13 // we are cross compiling for Nucleo-f401
johnAlexander 1:c1c10e0c32b2 57 InterruptIn stop_button(USER_BUTTON);
johnAlexander 1:c1c10e0c32b2 58 stop_button.rise(&StopMeasureIRQ);
johnAlexander 1:c1c10e0c32b2 59 #endif
johnAlexander 1:c1c10e0c32b2 60
johnAlexander 1:c1c10e0c32b2 61 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 0:cd8e818d4288 62 int status;
johnAlexander 1:c1c10e0c32b2 63
johnAlexander 0:cd8e818d4288 64 /* creates the 53L0A1 expansion board singleton obj */
johnAlexander 0:cd8e818d4288 65 board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);
johnAlexander 0:cd8e818d4288 66
johnAlexander 0:cd8e818d4288 67 board->display->DisplayString("53L0");
johnAlexander 0:cd8e818d4288 68 /* init the 53L0A1 expansion board with default values */
johnAlexander 1:c1c10e0c32b2 69 status = board->InitBoard();
johnAlexander 1:c1c10e0c32b2 70 if (status) printf("Failed to init board!\n\r");
johnAlexander 1:c1c10e0c32b2 71 operating_mode = range_single_shot_polling;
johnAlexander 1:c1c10e0c32b2 72 /* start the measure on sensor centre */
johnAlexander 1:c1c10e0c32b2 73 status = board->sensor_centre->StartMeasurement(operating_mode, NULL);
johnAlexander 1:c1c10e0c32b2 74 if (!status)
johnAlexander 0:cd8e818d4288 75 {
johnAlexander 1:c1c10e0c32b2 76 while (1) // infinite loop. can be broken by pressing Blue (User) button.
johnAlexander 0:cd8e818d4288 77 {
johnAlexander 1:c1c10e0c32b2 78 status = board->sensor_centre->GetMeasurement(operating_mode, &data_sensor_centre);
johnAlexander 1:c1c10e0c32b2 79 DisplayRefresh(data_sensor_centre);
johnAlexander 1:c1c10e0c32b2 80 if (int_stop_measure) // Blue Button isr was triggered
johnAlexander 0:cd8e818d4288 81 {
johnAlexander 1:c1c10e0c32b2 82 status = board->sensor_centre->StopMeasurement(operating_mode); // stop the measure and exit
johnAlexander 0:cd8e818d4288 83 int_stop_measure = false;
johnAlexander 0:cd8e818d4288 84 printf("\nProgram stopped!\n\n\r");
johnAlexander 0:cd8e818d4288 85 break;
johnAlexander 0:cd8e818d4288 86 }
johnAlexander 0:cd8e818d4288 87 }
johnAlexander 0:cd8e818d4288 88 }
johnAlexander 0:cd8e818d4288 89 board->display->DisplayString("BYE");
johnAlexander 0:cd8e818d4288 90 delete board;
johnAlexander 0:cd8e818d4288 91 }