modified to work with MultiTech mDot on UDK2.0

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of HelloWorld_53L0A1 by ST

Files at this revision

API Documentation at this revision

Comitter:
johnAlexander
Date:
Mon Nov 28 11:26:38 2016 +0000
Child:
1:3483e701ec59
Commit message:
Simple, singleshot, polled ranging example using the central sensor of an X_NUCLEO_53L0A1 expansion board.

Changed in this revision

X_NUCLEO_53L0A1.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_53L0A1.lib	Mon Nov 28 11:26:38 2016 +0000
@@ -0,0 +1,1 @@
+X_NUCLEO_53L0A1#c523920bcc09
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 28 11:26:38 2016 +0000
@@ -0,0 +1,160 @@
+#include "mbed.h"
+#include "x_nucleo_53l0a1.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+/* This VL6180X Expansion board test application performs a range measurement and an als measurement in interrupt mode
+   on the onboard embedded top sensor. 
+   The board red slider select on the flight the measurement type as ALS or RANGE; the measured data is diplayed on the 
+   on bord 4digits display.
+
+   User Blue button allows to stop current measurement and the entire program releasing all the resources.
+   Reset button is used to restart the program. */
+
+/* Polling operating modes don`t require callback function that handles IRQ 
+   Callback IRQ functions are used only for measure that require interrupt */
+
+/* GetMeasurement is asynchronous! It returns NOT_READY if the measurement value 
+   is not ready to be read from the corresponding register. So you need to wait
+   for the result to be ready */
+
+#define VL53L0_I2C_SDA   D14 
+#define VL53L0_I2C_SCL   D15 
+
+#define RANGE   0
+
+static X_NUCLEO_53L0A1 *board=NULL;
+VL53L0X_RangingMeasurementData_t data_sensor_centre;
+OperatingMode operating_mode, prev_operating_mode;
+	
+/* flags that handle interrupt request */
+bool int_sensor_centre=false, int_stop_measure=false;	
+
+/* ISR callback function of the sensor_centre */
+void SensorTopIRQ(void)
+{
+   int_sensor_centre=true;
+   board->sensor_centre->DisableInterruptMeasureDetectionIRQ();
+}	
+
+/* ISR callback function of the user blue button to stop program */
+void StopMeasureIRQ(void)
+{
+   int_stop_measure=true;
+}
+#define DELAY 100  // 100ms
+/* On board 4 digit local display refresh */
+void DisplayRefresh(OperatingMode op_mode)
+{   
+   Timer timer;
+   char str[5];
+   
+   if (op_mode==range_single_shot_polling || op_mode==range_continuous_interrupt || op_mode==range_continuous_polling)
+   {
+	  if (data_sensor_centre.RangeStatus == 0) // we have a valid range.
+      {
+         sprintf(str,"%d",data_sensor_centre.RangeMilliMeter);
+      }
+      else
+      {
+         sprintf(str,"%s","----");
+      }
+   }
+	 
+   board->display->DisplayString(str);
+/*
+   timer.start();
+   for(int i=0; i<DELAY; i=timer.read_ms())
+   {
+   }
+   timer.stop();
+*/
+}
+
+/* Print on USB Serial the started OperatingMode */
+/*
+void PrintStartMessage(OperatingMode op_mode)
+{
+   if(op_mode==range_continuous_interrupt)
+      printf("\nStarted range continuous interrupt measure\n\r");
+}
+*/
+
+/* Print on USB Serial the stopped OperatingMode */
+/*
+void PrintStopMessage(OperatingMode op_mode)
+{
+   if(op_mode==range_continuous_interrupt)
+      printf("Stopped range continuous interrupt measure\n\r");
+}
+*/
+/* Print on board 4 Digit display the indicated message <= 4 char */
+//#define DELAY 2000  // 2Sec
+/*
+void DisplayMsg(const char * msg)
+{
+   Timer timer;
+   char str[5];
+   
+   timer.start();
+   for(int i=0; i<DELAY; i=timer.read_ms())
+   {
+      sprintf(str,"%s",msg);
+      board->display->DisplayString(str);
+   }
+   timer.stop();
+}
+*/
+
+void ContinousRangeMeasure(DevI2C *device_i2c) {
+   int status;
+
+   /* creates the 53L0A1 expansion board singleton obj */
+   board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);
+	
+   board->display->DisplayString("53L0");
+   /* init the 53L0A1 expansion board with default values */
+   status=board->InitBoard();
+   if(status)
+      printf("Failed to init board!\n\r");   
+//   operating_mode=range_continuous_polling;
+   operating_mode=range_single_shot_polling;
+   /* start the measure on sensor top */
+   status=board->sensor_centre->StartMeasurement(operating_mode, SensorTopIRQ);
+   if(!status)
+   {
+      while(1)
+      {
+         status=board->sensor_centre->GetMeasurement(operating_mode, &data_sensor_centre);
+         DisplayRefresh(operating_mode);
+         if(int_stop_measure) // Blue Button isr was triggered
+         {
+            status=board->sensor_centre->StopMeasurement(operating_mode); // stop the measure and exit
+   			int_stop_measure = false;
+            printf("\nProgram stopped!\n\n\r");
+            break;
+         }
+      }
+   }
+   board->display->DisplayString("BYE");
+   delete board;	    
+}	 
+
+/*=================================== Main ==================================
+ Press the blue user button to stop the measurements in progress 	
+=============================================================================*/
+int main()
+{   
+#if USER_BUTTON==PC_13  // we are cross compiling for Nucleo-f401 
+   InterruptIn stop_button (USER_BUTTON);
+   stop_button.rise (&StopMeasureIRQ);	
+#endif   
+   DevI2C *device_i2c =new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);     
+		
+   ContinousRangeMeasure(device_i2c);  // start continuous measures
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 28 11:26:38 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85
\ No newline at end of file