Skip to content

Commit a7bdc27

Browse files
committed
Adding FIFO and DMP functionality
1 parent 72c2d3b commit a7bdc27

File tree

6 files changed

+326
-13
lines changed

6 files changed

+326
-13
lines changed

examples/Arduino/Example5_DMP/Example5_DMP.ino

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
***************************************************************/
1414
#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
1515

16-
//#define USE_SPI // Uncomment this to use SPI
16+
#define USE_SPI // Uncomment this to use SPI
1717

1818
#define SERIAL_PORT Serial
1919

@@ -34,8 +34,18 @@
3434

3535
void setup() {
3636

37-
SERIAL_PORT.begin(115200);
38-
while(!SERIAL_PORT){};
37+
SERIAL_PORT.begin(115200); // Start the serial console
38+
SERIAL_PORT.println(F("ICM-20948 Example"));
39+
40+
delay(100);
41+
42+
while (SERIAL_PORT.available()) // Make sure the serial RX buffer is empty
43+
SERIAL_PORT.read();
44+
45+
SERIAL_PORT.println(F("Press any key to continue..."));
46+
47+
while (!SERIAL_PORT.available()) // Wait for the user to press a key (send any serial character)
48+
;
3949

4050
#ifdef USE_SPI
4151
SPI_PORT.begin();
@@ -67,19 +77,53 @@ void setup() {
6777

6878
SERIAL_PORT.println("Device connected!");
6979

80+
myICM.enableDMP(); // Enable the DMP
81+
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
91+
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+
}
99+
70100
myICM.enableSensor(INV_ICM20948_SENSOR_GAME_ROTATION_VECTOR); // Enable the Game Rotation Vector
71101

72102
if( myICM.status == ICM_20948_Stat_Ok )
73103
SERIAL_PORT.println("INV_ICM20948_SENSOR_ROTATION_VECTOR enabled!");
74104
else
75105
{
76-
SERIAL_PORT.println("INV_ICM20948_SENSOR_ROTATION_VECTOR failed! Status is: ");
106+
SERIAL_PORT.print("INV_ICM20948_SENSOR_ROTATION_VECTOR failed! Status is: ");
77107
SERIAL_PORT.println( myICM.statusString() );
78108
}
79109
}
80110

81-
void loop() {
111+
void loop()
112+
{
113+
uint16_t count;
114+
myICM.getFIFOcount(&count);
115+
if( myICM.status == ICM_20948_Stat_Ok )
116+
{
117+
SERIAL_PORT.print("FIFO count is: ");
118+
SERIAL_PORT.println( count );
119+
}
120+
else
121+
{
122+
SERIAL_PORT.print("getFIFOcount failed! Status is: ");
123+
SERIAL_PORT.println( myICM.statusString() );
124+
}
82125

126+
delay(1000);
83127
}
84128

85129

src/ICM_20948.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,47 @@ ICM_20948_Status_e ICM_20948::writeMag(AK09916_Reg_Addr_e reg, uint8_t *pdata)
919919
return status;
920920
}
921921

922+
// FIFO
923+
924+
ICM_20948_Status_e ICM_20948::enableFIFO(bool enable)
925+
{
926+
status = ICM_20948_enable_FIFO(&_device, enable);
927+
return status;
928+
}
929+
930+
ICM_20948_Status_e ICM_20948::resetFIFO(void)
931+
{
932+
status = ICM_20948_reset_FIFO(&_device);
933+
return status;
934+
}
935+
936+
ICM_20948_Status_e ICM_20948::setFIFOmode(bool snapshot)
937+
{
938+
// Default to Stream (non-Snapshot) mode
939+
status = ICM_20948_set_FIFO_mode(&_device, snapshot);
940+
return status;
941+
}
942+
943+
ICM_20948_Status_e ICM_20948::getFIFOcount(uint16_t *count)
944+
{
945+
status = ICM_20948_get_FIFO_count(&_device, count);
946+
return status;
947+
}
948+
922949
// DMP
923950

951+
ICM_20948_Status_e ICM_20948::enableDMP(bool enable)
952+
{
953+
status = ICM_20948_enable_DMP(&_device, enable);
954+
return status;
955+
}
956+
957+
ICM_20948_Status_e ICM_20948::resetDMP(void)
958+
{
959+
status = ICM_20948_reset_DMP(&_device);
960+
return status;
961+
}
962+
924963
ICM_20948_Status_e ICM_20948::loadDMPFirmware(void)
925964
{
926965
status = ICM_20948_firmware_load(&_device);

src/ICM_20948.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ class ICM_20948
163163
uint8_t readMag(AK09916_Reg_Addr_e reg);
164164
ICM_20948_Status_e writeMag(AK09916_Reg_Addr_e reg, uint8_t *pdata);
165165

166+
//FIFO
167+
ICM_20948_Status_e enableFIFO(bool enable = true);
168+
ICM_20948_Status_e resetFIFO(void);
169+
ICM_20948_Status_e setFIFOmode(bool snapshot = false); // Default to Stream (non-Snapshot) mode
170+
ICM_20948_Status_e getFIFOcount(uint16_t *count);
171+
166172
//DMP
173+
ICM_20948_Status_e enableDMP(bool enable = true);
174+
ICM_20948_Status_e resetDMP(void);
167175
ICM_20948_Status_e loadDMPFirmware(void);
168176
ICM_20948_Status_e enableSensor(enum inv_icm20948_sensor sensor, bool enable = true);
169177
};

0 commit comments

Comments
 (0)