Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: VL53L1
Dependents: VL53L1CB_shield_sensor_polling VL53L1CB_MB2_NoShield_3sensors_interrupt_ranging VL53L1CB_MB5_NoShield_3sensors_interrupt_ranging VL53L1CB_MB5_NoShield_3sensors_interrupt_ranging
XNucleo53L1A2.cpp
00001 /* 00002 * *** NOTE : By default hardlinks U10, U11, U15 & U18, on the underside of 00003 * the X-NUCELO-53L1A1 expansion board are not made/OFF. 00004 * These links must be made to allow interrupts from the Satellite boards 00005 * to be received. 00006 * U11 and U18 must be made/ON to allow interrupts to be received from the 00007 * INT_L & INT_R positions; or 00008 * U10 and U15 must be made/ON to allow interrupts to be received from the 00009 * Alternate INT_L & INT_R positions. 00010 * The X_NUCLEO_53L1A2 library defaults to use the INT_L/INT_R positions. 00011 * INT_L is available on expansion board Arduino Connector CN5, pin 1 as D8. 00012 * Alternate INT_L is on CN5 Connector pin 2 as D9. 00013 * INT_R is available on expansion board Arduino Connector CN9, pin 3 as D2. 00014 * Alternate INT_R is on CN9 Connector pin 5 as D4. 00015 * The pinouts are shown here : https://developer.mbed.org/components/X-NUCLEO-53L1A2/ 00016 */ 00017 00018 #include "XNucleo53L1A2.h" 00019 00020 XNucleo53L1A2 *XNucleo53L1A2::_instance = NULL; 00021 00022 00023 XNucleo53L1A2 *XNucleo53L1A2::instance(ToF_DevI2C *ext_i2c) 00024 { 00025 if (_instance == NULL) { 00026 _instance = new XNucleo53L1A2(ext_i2c); 00027 } else { 00028 printf("Failed to create XNucleo53L1A2 instance\n\r\r\n"); 00029 } 00030 return _instance; 00031 } 00032 00033 XNucleo53L1A2 *XNucleo53L1A2::instance(ToF_DevI2C *ext_i2c, 00034 PinName gpio1_centre, 00035 PinName gpio1_left, PinName gpio1_right) 00036 { 00037 if (_instance == NULL) { 00038 // printf("instance %d z\n",ext_i2c); 00039 _instance = new XNucleo53L1A2(ext_i2c, gpio1_centre, gpio1_left, gpio1_right); 00040 } else { 00041 printf("Failed to create XNucleo53L0A1 instance\n\r"); 00042 } 00043 return _instance; 00044 } 00045 00046 00047 int XNucleo53L1A2::init_board() 00048 { 00049 int status, n_dev = 0; 00050 00051 sensor_centre->VL53L1CB_Off(); 00052 sensor_left->VL53L1CB_Off(); 00053 sensor_right->VL53L1CB_Off(); 00054 int i = 0; 00055 00056 // On startup or on the shutdown pin going high the VL53l1 devices have a i2c address of 0x52. 00057 // To initialise then we have to bring up one device at a time This involves raising the shutdown pin for that device, 00058 // initialising then setting the i2c address to a unique value. Once that is done the shutdown pins don't need to be touched. 00059 00060 // set the shutdown pins to be outputs ( they are inputs on power up) 00061 stmpe1600_exp1->set_gpio_dir(GPIO_15,OUTPUT); 00062 stmpe1600_exp0->set_gpio_dir(GPIO_14,OUTPUT); 00063 stmpe1600_exp0->set_gpio_dir(GPIO_15,OUTPUT); 00064 00065 // set the shutdown pins to low, this will reset the VL53l1s 00066 stmpe1600_exp1->clear_gpio(GPIO_15); 00067 stmpe1600_exp0->clear_gpio(GPIO_14); 00068 stmpe1600_exp0->clear_gpio(GPIO_15); 00069 00070 // select the first VL53l1. It will have i2c address of 0x52. Set the i2c address to 00071 //NEW_SENSOR_CENTRE_ADDRESS 00072 stmpe1600_exp1->set_gpio(GPIO_15); 00073 status = sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS); 00074 if (status) { 00075 delete sensor_centre; 00076 delete xshutdown_centre; 00077 sensor_centre = NULL; 00078 xshutdown_centre = NULL; 00079 printf("Sensor centre not present\n\r"); 00080 } else { 00081 printf("Sensor centre present\n\r"); 00082 n_dev++; 00083 } 00084 #if (MBED_VERSION > 60300) 00085 thread_sleep_for(2); 00086 #else 00087 wait_ms(2); // NEEDS A DELAY BETWEEN SENSORS 00088 #endif 00089 00090 // select the second VL53l1. It will have i2c address of 0x52. Set the i2c address to 00091 //NEW_SENSOR_LEFT_ADDRESS 00092 00093 stmpe1600_exp0->set_gpio(GPIO_14); 00094 00095 status = sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS); 00096 if (status) { 00097 delete sensor_left; 00098 delete xshutdown_left; 00099 sensor_left = NULL; 00100 xshutdown_left = NULL; 00101 printf("Sensor left not present\n\r"); 00102 } else { 00103 printf("Sensor left present\n\r"); 00104 n_dev++; 00105 } 00106 00107 #if (MBED_VERSION > 60300) 00108 thread_sleep_for(50); 00109 #else 00110 wait_ms(50); // NEEDS A DELAY BETWEEN SENSORS 00111 #endif 00112 // select the 3rd VL53l1. It will have i2c address of 0x52. Set the i2c address to 00113 //NEW_SENSOR_RIGHT_ADDRESS 00114 stmpe1600_exp0->set_gpio(GPIO_15); 00115 status = sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS); 00116 if (status) { 00117 delete sensor_right; 00118 delete xshutdown_right; 00119 sensor_right = NULL; 00120 xshutdown_right = NULL; 00121 printf("Sensor right not present\n\r"); 00122 } else { 00123 printf("Sensor right present\n\r"); 00124 n_dev++; 00125 } 00126 #if (MBED_VERSION > 60300) 00127 thread_sleep_for(50); 00128 #else 00129 wait_ms(50); // NEEDS A DELAY BETWEEN SENSORS 00130 #endif 00131 if (n_dev == 0) { 00132 return 1; 00133 } else { 00134 return 0; 00135 } 00136 }
Generated on Sat Jul 30 2022 13:20:03 by
1.7.2