Skip to content

Commit 0898554

Browse files
committed
Improve initialization routine in examples
1 parent 018bdc4 commit 0898554

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

examples/Arduino/Example1_Basics/Example1_Basics.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@
2929
#else
3030
ICM_20948_I2C myICM; // Otherwise create an ICM_20948_I2C object
3131
#endif
32-
32+
3333

3434
void setup() {
3535

3636
SERIAL_PORT.begin(115200);
3737
while(!SERIAL_PORT){};
38+
39+
#ifdef USE_SPI
40+
SPI_PORT.begin();
41+
#else
42+
WIRE_PORT.begin();
43+
WIRE_PORT.setClock(400000);
44+
#endif
3845

3946
bool initialized = false;
4047
while( !initialized ){
4148

4249
#ifdef USE_SPI
43-
SPI_PORT.begin();
4450
myICM.begin( CS_PIN, SPI_PORT );
4551
#else
46-
WIRE_PORT.begin();
47-
WIRE_PORT.setClock(400000);
4852
myICM.begin( WIRE_PORT, AD0_VAL );
4953
#endif
5054

examples/Arduino/Example2_Advanced/Example2_Advanced.ino

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@
3434
void setup() {
3535

3636
SERIAL_PORT.begin(115200);
37-
while(!SERIAL_PORT){};
37+
while(!SERIAL_PORT){};
38+
39+
#ifdef USE_SPI
40+
SPI_PORT.begin();
41+
#else
42+
WIRE_PORT.begin();
43+
WIRE_PORT.setClock(400000);
44+
#endif
3845

3946
bool initialized = false;
4047
while( !initialized ){
4148

4249
#ifdef USE_SPI
43-
SPI_PORT.begin();
4450
myICM.begin( CS_PIN, SPI_PORT );
4551
#else
46-
WIRE_PORT.begin();
47-
WIRE_PORT.setClock(400000);
4852
myICM.begin( WIRE_PORT, AD0_VAL );
4953
#endif
5054

@@ -57,6 +61,7 @@ void setup() {
5761
initialized = true;
5862
}
5963
}
64+
}
6065

6166
// In this advanced example we'll cover how to do a more fine-grained setup of your sensor
6267
SERIAL_PORT.println("Device connected!");

0 commit comments

Comments
 (0)