Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SW reboot for BMI270, retry BMI270 init in case of failure #682

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 55 additions & 37 deletions libraries/NDP/examples/SensorTest/SensorTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int loopCounter = 0;
void setup() {
int s;
uint8_t __attribute__((aligned(4))) sensor_data[16];
int retry_sensor_init = 0;

Serial.begin(115200);
nicla::begin();
Expand All @@ -56,51 +57,68 @@ void setup() {
NDP.turnOnMicrophone();
NDP.interrupts();

// 1st read will place the sensor in SPI mode, 2nd read is real read
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);
do {
if (retry_sensor_init) {
Serial.print("Reinit attempt ");
Serial.println(retry_sensor_init);
}
// 1st read will place the sensor in SPI mode, 2nd read is real read
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);

s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);
Serial.print("BMI270 chip ID is (expected is 0x24): ");
Serial.println(sensor_data[0], HEX);
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);
Serial.print("BMI270 chip ID is (expected is 0x24): ");
Serial.println(sensor_data[0], HEX);

// soft reset
s = NDP.sensorBMI270Write(0x7e, 0x6b);
CHECK_STATUS(s);
delay(20); //delay 20ms much longer than reqired 450us
// soft reset
s = NDP.sensorBMI270Write(0x7e, 0xb6);
CHECK_STATUS(s);
delay(20);

// back to SPI mode after software reset
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);
// back to SPI mode after software reset
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);
s = NDP.sensorBMI270Read(0x0, 1, sensor_data);
CHECK_STATUS(s);

// disable PWR_CONF.adv_power_save
s = NDP.sensorBMI270Write(0x7c, 0x00);
CHECK_STATUS(s);
delay(20); //delay 20ms much longer than reqired 450us
s = NDP.sensorBMI270Read(0x21, 1, sensor_data);
CHECK_STATUS(s);
Serial.print("[After reset] BMI270 Status Register at address 0x21 is (expected is 0x00): 0x");
Serial.println(sensor_data[0], HEX);

// prepare config load INIT_CTRL = 0x00
s = NDP.sensorBMI270Write(0x59, 0x00);
CHECK_STATUS(s);
// disable PWR_CONF.adv_power_save
s = NDP.sensorBMI270Write(0x7c, 0x00);
CHECK_STATUS(s);
delay(20);

// burst write to INIT_DATA
Serial.print("BMI270 init starting...");
s = NDP.sensorBMI270Write(0x5e,
sizeof(bmi270_maximum_fifo_config_file),
(uint8_t*)bmi270_maximum_fifo_config_file);
CHECK_STATUS(s);
Serial.println("... done!");
// prepare config load INIT_CTRL = 0x00
s = NDP.sensorBMI270Write(0x59, 0x00);
CHECK_STATUS(s);
delay(200);

s = NDP.sensorBMI270Write(0x59, 0x01);
CHECK_STATUS(s);
delay(200);
// burst write to INIT_DATA
Serial.print("BMI270 init starting...");
s = NDP.sensorBMI270Write(0x5e,
sizeof(bmi270_maximum_fifo_config_file),
(uint8_t*)bmi270_maximum_fifo_config_file);
CHECK_STATUS(s);
Serial.println("... done!");

s = NDP.sensorBMI270Read(0x21, 1, sensor_data);
CHECK_STATUS(s);
Serial.print("BMI270 Status Register at address 0x21 is (expected is 0x01): 0x");
Serial.println(sensor_data[0], HEX);
s = NDP.sensorBMI270Write(0x59, 0x01);
CHECK_STATUS(s);
delay(200);

s = NDP.sensorBMI270Read(0x21, 1, sensor_data);
CHECK_STATUS(s);
Serial.print("BMI270 Status Register at address 0x21 is (expected is 0x01): 0x");
Serial.println(sensor_data[0], HEX);
if (sensor_data[0] != 1) {
retry_sensor_init++;
} else {
retry_sensor_init = 0;
}
} while (retry_sensor_init);

// configuring device to normal power mode with both Accelerometer and gyroscope working
s = NDP.sensorBMI270Write(0x7d, 0x0e);
Expand Down
2 changes: 1 addition & 1 deletion libraries/syntiant_ilib/src/syntiant_tiny_cspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define SYNTIANT_NDP120_SPI_OP 0
#define SYNTIANT_NDP120_MCU_OP 1

#define MSPI_CLK_DIV 2
#define MSPI_CLK_DIV 6
#define MSSB_OE_USED 7

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