Skip to content

Commit 4a550c7

Browse files
cvejlbofacchinm
authored andcommitted
Configure NDP clock after loading 2 FW synpkgs.
Refactor Controller SPI handling for sensor handling
1 parent 01504d5 commit 4a550c7

File tree

9 files changed

+888
-333
lines changed

9 files changed

+888
-333
lines changed

libraries/NDP/examples/AlexaDemo/AlexaDemo.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ void setup() {
4949
NDP.load("alexa_334_NDP120_B0_v11_v91.synpkg");
5050
Serial.println("packages loaded");
5151
NDP.getInfo();
52-
Serial.println("Configure clock");
52+
Serial.println("Configure mic");
5353
NDP.turnOnMicrophone();
5454
NDP.interrupts();
5555

56-
// For maximum low power; please note that it's impossible to print afer calling these functions
56+
// For maximum low power; please note that it's impossible to print after calling these functions
5757
nicla::leds.end();
5858
if (lowestPower) {
5959
NRF_UART0->ENABLE = 0;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Configuration file for BMI270
2+
const uint8_t bmi270_maximum_fifo_config_file[] = {
3+
0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x1a, 0x00, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e,
4+
0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e,
5+
0x90, 0x32, 0x21, 0x2e, 0x59, 0xf5, 0x10, 0x30, 0x21, 0x2e, 0x6a, 0xf5, 0x1a, 0x24, 0x22, 0x00,
6+
0x80, 0x2e, 0x3b, 0x00, 0xc8, 0x2e, 0x44, 0x47, 0x22, 0x00, 0x37, 0x00, 0xa4, 0x00, 0xff, 0x0f,
7+
0xd1, 0x00, 0x07, 0xad, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1,
8+
0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1,
9+
0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1,
10+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x24, 0xfc, 0xf5, 0x80, 0x30, 0x40, 0x42, 0x50, 0x50,
11+
0x00, 0x30, 0x12, 0x24, 0xeb, 0x00, 0x03, 0x30, 0x00, 0x2e, 0xc1, 0x86, 0x5a, 0x0e, 0xfb, 0x2f,
12+
0x21, 0x2e, 0xfc, 0xf5, 0x13, 0x24, 0x63, 0xf5, 0xe0, 0x3c, 0x48, 0x00, 0x22, 0x30, 0xf7, 0x80,
13+
0xc2, 0x42, 0xe1, 0x7f, 0x3a, 0x25, 0xfc, 0x86, 0xf0, 0x7f, 0x41, 0x33, 0x98, 0x2e, 0xc2, 0xc4,
14+
0xd6, 0x6f, 0xf1, 0x30, 0xf1, 0x08, 0xc4, 0x6f, 0x11, 0x24, 0xff, 0x03, 0x12, 0x24, 0x00, 0xfc,
15+
0x61, 0x09, 0xa2, 0x08, 0x36, 0xbe, 0x2a, 0xb9, 0x13, 0x24, 0x38, 0x00, 0x64, 0xbb, 0xd1, 0xbe,
16+
0x94, 0x0a, 0x71, 0x08, 0xd5, 0x42, 0x21, 0xbd, 0x91, 0xbc, 0xd2, 0x42, 0xc1, 0x42, 0x00, 0xb2,
17+
0xfe, 0x82, 0x05, 0x2f, 0x50, 0x30, 0x21, 0x2e, 0x21, 0xf2, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e,
18+
0xf0, 0x6f, 0x02, 0x30, 0x02, 0x42, 0x20, 0x26, 0xe0, 0x6f, 0x02, 0x31, 0x03, 0x40, 0x9a, 0x0a,
19+
0x02, 0x42, 0xf0, 0x37, 0x05, 0x2e, 0x5e, 0xf7, 0x10, 0x08, 0x12, 0x24, 0x1e, 0xf2, 0x80, 0x42,
20+
0x83, 0x84, 0xf1, 0x7f, 0x0a, 0x25, 0x13, 0x30, 0x83, 0x42, 0x3b, 0x82, 0xf0, 0x6f, 0x00, 0x2e,
21+
0x00, 0x2e, 0xd0, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x00, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x3e, 0x84,
22+
0x00, 0x40, 0x40, 0x42, 0x7e, 0x82, 0xe1, 0x7f, 0xf2, 0x7f, 0x98, 0x2e, 0x6a, 0xd6, 0x21, 0x30,
23+
0x23, 0x2e, 0x61, 0xf5, 0xeb, 0x2c, 0xe1, 0x6f
24+
};
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#include "NDP.h"
2+
3+
#include "BMI270_Init.h"
4+
5+
void ledBlueOn(char* label) {
6+
nicla::leds.begin();
7+
nicla::leds.setColor(blue);
8+
delay(200);
9+
nicla::leds.setColor(off);
10+
Serial.println(label);
11+
nicla::leds.end();
12+
}
13+
14+
void ledGreenOn() {
15+
nicla::leds.begin();
16+
nicla::leds.setColor(green);
17+
delay(200);
18+
nicla::leds.setColor(off);
19+
nicla::leds.end();
20+
}
21+
22+
void ledRedBlink() {
23+
while (1) {
24+
nicla::leds.begin();
25+
nicla::leds.setColor(red);
26+
delay(200);
27+
nicla::leds.setColor(off);
28+
delay(200);
29+
nicla::leds.end();
30+
}
31+
}
32+
33+
int loopCounter = 0;
34+
35+
#define CHECK_STATUS(s) do { if (s) {Serial.print("SPI access error in line "); Serial.println(__LINE__); for(;;);}} while (0)
36+
37+
void setup() {
38+
int s;
39+
uint8_t __attribute__((aligned(4))) sensor_data[16];
40+
41+
Serial.begin(115200);
42+
nicla::begin();
43+
nicla::disableLDO();
44+
nicla::leds.begin();
45+
46+
NDP.onError(ledRedBlink);
47+
NDP.onMatch(ledBlueOn);
48+
NDP.onEvent(ledGreenOn);
49+
Serial.println("Loading synpackages");
50+
NDP.begin("mcu_fw_120_v91.synpkg");
51+
NDP.load("dsp_firmware_v91.synpkg");
52+
NDP.load("alexa_334_NDP120_B0_v11_v91.synpkg");
53+
Serial.println("packages loaded");
54+
NDP.getInfo();
55+
Serial.println("Configure clock");
56+
NDP.turnOnMicrophone();
57+
NDP.interrupts();
58+
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);
62+
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);
67+
68+
// soft reset
69+
s = NDP.sensorBMI270Write(0x7e, 0x6b);
70+
CHECK_STATUS(s);
71+
delay(20); //delay 20ms much longer than reqired 450us
72+
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);
78+
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
83+
84+
// prepare config load INIT_CTRL = 0x00
85+
s = NDP.sensorBMI270Write(0x59, 0x00);
86+
CHECK_STATUS(s);
87+
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+
96+
s = NDP.sensorBMI270Write(0x59, 0x01);
97+
CHECK_STATUS(s);
98+
delay(200);
99+
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);
104+
105+
// configuring device to normal power mode with both Accelerometer and gyroscope working
106+
s = NDP.sensorBMI270Write(0x7d, 0x0e);
107+
CHECK_STATUS(s);
108+
s = NDP.sensorBMI270Write(0x40, 0xa8);
109+
CHECK_STATUS(s);
110+
s = NDP.sensorBMI270Write(0x41, 0x00); // +/- 2g
111+
CHECK_STATUS(s);
112+
s = NDP.sensorBMI270Write(0x42, 0xa9); // odr 200, OSR2, noise ulp, filter hp
113+
CHECK_STATUS(s);
114+
s = NDP.sensorBMI270Write(0x43, 0x11); // gyr range_1000, ois range_2000
115+
CHECK_STATUS(s);
116+
s = NDP.sensorBMI270Write(0x7c, 0x02);
117+
118+
s = NDP.sensorBMM150Write(0x4b, 0x01);
119+
CHECK_STATUS(s);
120+
delay(20);
121+
s = NDP.sensorBMM150Read(0x4b, 1, sensor_data);
122+
CHECK_STATUS(s);
123+
Serial.print("BMM150 power control byte at address 0x4B is (expected is 0x01): 0x");
124+
Serial.println(sensor_data[0], HEX);
125+
126+
s = NDP.sensorBMM150Write(0x4c, 0x00);
127+
CHECK_STATUS(s);
128+
129+
s = NDP.sensorBMM150Read(0x40, 1, sensor_data);
130+
CHECK_STATUS(s);
131+
Serial.print("BMM150 chip ID at address 0x40 is (expected is 0x32): 0x");
132+
Serial.println(sensor_data[0], HEX);
133+
}
134+
135+
#define NUM_LOOPS_PER_SENSOR 15
136+
void loop() {
137+
uint8_t __attribute__((aligned(4))) sensor_data[16];
138+
139+
int16_t x_acc, y_acc, z_acc, x_gyr, y_gyr, z_gyr ;
140+
int16_t x_mag, y_mag, z_mag, hall;
141+
int s;
142+
143+
if (loopCounter < NUM_LOOPS_PER_SENSOR) {
144+
if (!loopCounter) {
145+
Serial.println("\nTesting Nicla Voice BMI270 Sensor");
146+
}
147+
148+
s = NDP.sensorBMI270Read(0xc, 16, &sensor_data[0]);
149+
CHECK_STATUS(s);
150+
x_acc = (0x0000 | sensor_data[0] | sensor_data[1] << 8);
151+
y_acc = (0x0000 | sensor_data[2] | sensor_data[3] << 8);
152+
z_acc = (0x0000 | sensor_data[4] | sensor_data[5] << 8);
153+
x_gyr = (0x0000 | sensor_data[6] | sensor_data[7] << 8);
154+
y_gyr = (0x0000 | sensor_data[8] | sensor_data[9] << 8);
155+
z_gyr = (0x0000 | sensor_data[10] | sensor_data[11]<< 8);
156+
157+
Serial.print("\rBMI270 data: Acc X/Y/Z Gyr X/Y/Z ");
158+
Serial.print(x_acc);
159+
Serial.print(" , ");
160+
Serial.print(y_acc);
161+
Serial.print(" , ");
162+
Serial.print(z_acc);
163+
Serial.print(" , ");
164+
Serial.print(x_gyr);
165+
Serial.print(" , ");
166+
Serial.print(y_gyr);
167+
Serial.print(" , ");
168+
Serial.print(z_gyr);
169+
Serial.println();
170+
} else if (loopCounter == NUM_LOOPS_PER_SENSOR) {
171+
Serial.println("\nTesting Nicla Voice BMM150 Sensor");
172+
} else { // loopCounter > NUM_LOOPS_PER_SENSOR
173+
s = NDP.sensorBMM150Read(0x42, 8, sensor_data);
174+
CHECK_STATUS(s);
175+
x_mag = (0x0000 | sensor_data[0] >> 3 | sensor_data[1] << 5);
176+
y_mag = (0x0000 | sensor_data[2] >> 3 | sensor_data[3] << 5);
177+
z_mag = (0x0000 | sensor_data[4] >> 1 | sensor_data[5] << 7);
178+
hall = (0x0000 | sensor_data[6] >> 2 | sensor_data[7] << 6);
179+
180+
Serial.print("\rBMM150 data: Mag X, Mag Y, Mag Z, Hall ");
181+
Serial.print(x_mag);
182+
Serial.print(" , ");
183+
Serial.print(y_mag);
184+
Serial.print(" , ");
185+
Serial.print(z_mag);
186+
Serial.print(" , ");
187+
Serial.print(hall);
188+
Serial.println();
189+
}
190+
delay(100);
191+
192+
if (++loopCounter > 2 * NUM_LOOPS_PER_SENSOR) {
193+
loopCounter = 0;
194+
}
195+
}

0 commit comments

Comments
 (0)