Skip to content

Commit fb8531f

Browse files
authored
Merge pull request #682 from cvejlbo/fix-bmi270-init
Nicla Voice: Fix SW reboot for BMI270, retry BMI270 init in case of failure
2 parents 8031008 + 2c3ab2e commit fb8531f

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

libraries/NDP/examples/SensorTest/SensorTest.ino

+55-37
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ int loopCounter = 0;
3737
void setup() {
3838
int s;
3939
uint8_t __attribute__((aligned(4))) sensor_data[16];
40+
int retry_sensor_init = 0;
4041

4142
Serial.begin(115200);
4243
nicla::begin();
@@ -56,51 +57,68 @@ void setup() {
5657
NDP.turnOnMicrophone();
5758
NDP.interrupts();
5859

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);
6268

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);
6773

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);
7278

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);
7884

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);
8389

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);
8794

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);
9599

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!");
99107

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);
104122

105123
// configuring device to normal power mode with both Accelerometer and gyroscope working
106124
s = NDP.sensorBMI270Write(0x7d, 0x0e);

libraries/syntiant_ilib/src/syntiant_tiny_cspi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define SYNTIANT_NDP120_SPI_OP 0
4040
#define SYNTIANT_NDP120_MCU_OP 1
4141

42-
#define MSPI_CLK_DIV 2
42+
#define MSPI_CLK_DIV 6
4343
#define MSSB_OE_USED 7
4444

4545
static int _cspi_read(struct syntiant_ndp120_tiny_device_s *ndp, int ssb, int num_bytes, uint8_t *data, int end_packet);

0 commit comments

Comments
 (0)