You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* ** This example is based on the InvenSense Application Note "Programming Sequence for DMP Hardware Functions".
11
+
* ** We are grateful to InvenSense for providing this.
12
+
*
13
+
* ** Important note: by default the DMP functionality is disabled in the library. This is to save program memory.
14
+
* ** The DMP firmware takes up 14290 Bytes of program memory. To use the DMP, you will need to:
15
+
* ** Edit ICM_20948_C.h
16
+
* ** Uncomment line 29: #define ICM_20948_USE_DMP
17
+
* ** Save changes
18
+
* ** If you are using Windows, you can find ICM_20948_C.h in Documents\Arduino\libraries\SparkFun_ICM-20948_ArduinoLibrary\src\util
9
19
*
10
20
* Please see License.md for the license information.
11
21
*
@@ -59,6 +69,8 @@ void setup() {
59
69
bool initialized = false;
60
70
while( !initialized ){
61
71
72
+
// Initialize the ICM-20948
73
+
// If the DMP is enabled, .begin performs a minimal startup. We need to configure the sample mode etc. manually.
62
74
#ifdef USE_SPI
63
75
myICM.begin( CS_PIN, SPI_PORT );
64
76
#else
@@ -77,35 +89,121 @@ void setup() {
77
89
78
90
SERIAL_PORT.println("Device connected!");
79
91
80
-
myICM.enableDMP(); //Enable the DMP
92
+
//The ICM-20948 is awake and ready but hasn't been configured. Let's step through the configuration
81
93
82
-
if( myICM.status == ICM_20948_Stat_Ok )
83
-
SERIAL_PORT.println("DMP enabled!");
84
-
else
85
-
{
86
-
SERIAL_PORT.print("Enable DMP failed! Status is: ");
87
-
SERIAL_PORT.println( myICM.statusString() );
88
-
}
89
-
90
-
myICM.enableFIFO(); // Enable the FIFO
94
+
bool success = true; // Use success to show if the configuration was successful
91
95
92
-
if( myICM.status == ICM_20948_Stat_Ok )
93
-
SERIAL_PORT.println("FIFO enabled!");
94
-
else
95
-
{
96
-
SERIAL_PORT.print("Enable FIFO failed! Status is: ");
97
-
SERIAL_PORT.println( myICM.statusString() );
98
-
}
96
+
// Configure clock source through PWR_MGMT_1
97
+
// Auto selects the best available clock source – PLL if ready, else use the Internal oscillator
98
+
success &= (myICM.setClockSource(ICM_20948_Clock_Auto) == ICM_20948_Stat_Ok); // This is shorthand: success will be set to false if setClockSource fails
99
+
100
+
// Enable accel and gyro sensors through PWR_MGMT_2
101
+
// Enable Accelerometer (all axes) and Gyroscope (all axes) by writing zero to PWR_MGMT_2
102
+
uint8_t zero = 0;
103
+
success &= (myICM.write(AGB0_REG_PWR_MGMT_2, &zero, 1) == ICM_20948_Stat_Ok); // Write one byte to the PWR_MGMT_2 register
104
+
105
+
// Configure Gyro/Accel in Low power mode with LP_CONFIG
ICM_20948_Status_e startupDefault(bool minimal = false); // If minimal is true, several startup steps are skipped. If ICM_20948_USE_DMP is defined, .begin will call startupDefault with minimal set to true.
0 commit comments