@@ -37,6 +37,7 @@ int loopCounter = 0;
37
37
void setup () {
38
38
int s;
39
39
uint8_t __attribute__ ((aligned (4 ))) sensor_data[16 ];
40
+ int retry_sensor_init = 0 ;
40
41
41
42
Serial.begin (115200 );
42
43
nicla::begin ();
@@ -56,51 +57,68 @@ void setup() {
56
57
NDP.turnOnMicrophone ();
57
58
NDP.interrupts ();
58
59
59
- // 1st read will place the sensor in SPI mode, 2nd read is real read
60
- s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
61
- CHECK_STATUS (s);
60
+ do {
61
+ if (retry_sensor_init) {
62
+ Serial.print (" Reinit attempt " );
63
+ Serial.println (retry_sensor_init);
64
+ }
65
+ // 1st read will place the sensor in SPI mode, 2nd read is real read
66
+ s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
67
+ CHECK_STATUS (s);
62
68
63
- s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
64
- CHECK_STATUS (s);
65
- Serial.print (" BMI270 chip ID is (expected is 0x24): " );
66
- Serial.println (sensor_data[0 ], HEX);
69
+ s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
70
+ CHECK_STATUS (s);
71
+ Serial.print (" BMI270 chip ID is (expected is 0x24): " );
72
+ Serial.println (sensor_data[0 ], HEX);
67
73
68
- // soft reset
69
- s = NDP.sensorBMI270Write (0x7e , 0x6b );
70
- CHECK_STATUS (s);
71
- delay (20 ); // delay 20ms much longer than reqired 450us
74
+ // soft reset
75
+ s = NDP.sensorBMI270Write (0x7e , 0xb6 );
76
+ CHECK_STATUS (s);
77
+ delay (20 );
72
78
73
- // back to SPI mode after software reset
74
- s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
75
- CHECK_STATUS (s);
76
- s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
77
- CHECK_STATUS (s);
79
+ // back to SPI mode after software reset
80
+ s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
81
+ CHECK_STATUS (s);
82
+ s = NDP.sensorBMI270Read (0x0 , 1 , sensor_data);
83
+ CHECK_STATUS (s);
78
84
79
- // disable PWR_CONF.adv_power_save
80
- s = NDP. sensorBMI270Write ( 0x7c , 0x00 );
81
- CHECK_STATUS (s );
82
- delay ( 20 ); // delay 20ms much longer than reqired 450us
85
+ s = NDP. sensorBMI270Read ( 0x21 , 1 , sensor_data);
86
+ CHECK_STATUS (s );
87
+ Serial. print ( " [After reset] BMI270 Status Register at address 0x21 is (expected is 0x00): 0x " );
88
+ Serial. println (sensor_data[ 0 ], HEX);
83
89
84
- // prepare config load INIT_CTRL = 0x00
85
- s = NDP.sensorBMI270Write (0x59 , 0x00 );
86
- CHECK_STATUS (s);
90
+ // disable PWR_CONF.adv_power_save
91
+ s = NDP.sensorBMI270Write (0x7c , 0x00 );
92
+ CHECK_STATUS (s);
93
+ delay (20 );
87
94
88
- // burst write to INIT_DATA
89
- Serial.print (" BMI270 init starting..." );
90
- s = NDP.sensorBMI270Write (0x5e ,
91
- sizeof (bmi270_maximum_fifo_config_file),
92
- (uint8_t *)bmi270_maximum_fifo_config_file);
93
- CHECK_STATUS (s);
94
- Serial.println (" ... done!" );
95
+ // prepare config load INIT_CTRL = 0x00
96
+ s = NDP.sensorBMI270Write (0x59 , 0x00 );
97
+ CHECK_STATUS (s);
98
+ delay (200 );
95
99
96
- s = NDP.sensorBMI270Write (0x59 , 0x01 );
97
- CHECK_STATUS (s);
98
- delay (200 );
100
+ // burst write to INIT_DATA
101
+ Serial.print (" BMI270 init starting..." );
102
+ s = NDP.sensorBMI270Write (0x5e ,
103
+ sizeof (bmi270_maximum_fifo_config_file),
104
+ (uint8_t *)bmi270_maximum_fifo_config_file);
105
+ CHECK_STATUS (s);
106
+ Serial.println (" ... done!" );
99
107
100
- s = NDP.sensorBMI270Read (0x21 , 1 , sensor_data);
101
- CHECK_STATUS (s);
102
- Serial.print (" BMI270 Status Register at address 0x21 is (expected is 0x01): 0x" );
103
- Serial.println (sensor_data[0 ], HEX);
108
+ s = NDP.sensorBMI270Write (0x59 , 0x01 );
109
+ CHECK_STATUS (s);
110
+ delay (200 );
111
+
112
+ s = NDP.sensorBMI270Read (0x21 , 1 , sensor_data);
113
+ CHECK_STATUS (s);
114
+ Serial.print (" BMI270 Status Register at address 0x21 is (expected is 0x01): 0x" );
115
+ Serial.println (sensor_data[0 ], HEX);
116
+ if (sensor_data[0 ] != 1 ) {
117
+ retry_sensor_init++;
118
+ } else {
119
+ retry_sensor_init = 0 ;
120
+ }
121
+ } while (retry_sensor_init);
104
122
105
123
// configuring device to normal power mode with both Accelerometer and gyroscope working
106
124
s = NDP.sensorBMI270Write (0x7d , 0x0e );
0 commit comments