Skip to content

ICM20948

ICM20948 9-axis IMU service using SPI and DMP FIFO acquisition triggered by a data-ready interrupt.

Publishes accelerometer, gyroscope and quaternion data through PUBSUB using a dynamically assigned KPID. Magnetometer data is processed internally but is not included in the published payload.


Files

File Description
icm20948.h Public API, register map, ICM20948_t context struct
icm20948.c Driver implementation, DMP loading, service task
dmpImage.h DMP firmware binary image (do not edit)

Registration

The driver maintains a static ICM20948_t instance internally and exposes its producer contract through:

const SPP_SERVICE_ProducerContract_t *SPP_SERVICES_ICM20948_getProducerContract(void);

The application registers this contract through SPP_SERVICES_PUBSUB_registerProducer().

The producer implements init() and acquireData() callbacks. Data acquisition is triggered by the GPIO data-ready interrupt.


Register banks

The ICM20948 has four register banks (0–3) selected via register 0x7F. The driver handles bank switching transparently — do not write to 0x7F directly.


DMP support

The DMP firmware (dmpImage.h) is loaded into the sensor's RAM at init time. Current config: - DATA_OUT_CTL1 = 0x8400 → Accel + Quat9 only - Packet size = 24 bytes: Header(2) + Accel(6) + Quat9(14) + Footer(2)

Disable DMP at build time with -DSPP_ICM20948_NO_DMP=1 to save ~14 KB of flash.


Registration

extern const SPP_Module_t g_icm20948Module;

static ICM20948_t s_icm = {
    .spiDevIdx   = 0U,
    .intPin      = 10U,
    .intIntrType = 1U,   // rising edge
    .intPull     = 0U,   // no pull
};

SPP_SERVICES_register(&g_icm20948Module, &s_icm);

register() calls init (loads DMP firmware, installs ISR) and start immediately.


Packet payload layout (44 bytes)

Offset Type Field
0 float Accel X (g)
4 float Accel Y (g)
8 float Accel Z (g)
12 float Gyro X (dps)
16 float Gyro Y (dps)
20 float Gyro Z (dps)
24 float Quaternion W
28 float Quaternion X
32 float Quaternion Y
36 float Quaternion Z
40 float Quaternion accuracy

Hardware configuration (ESP32-S3)

  • SPI device index: 1 (CS GPIO 21, 1 MHz, MODE0).
  • DRDY interrupt: GPIO 4, rising edge.
  • Accelerometer range: ±4g.
  • Gyroscope range: ±1000 dps.
  • WHO_AM_I: 0xEA.