3 * @brief I2C interrupt example for the 7Semi ICM-20948.
4 * @details Configures the IMU raw-data-ready interrupt pin and counts ISR
5 * events on an Arduino-compatible board.
9#include <DevLab_ICM20948.h>
11/** @brief I2C SDA pin used by the example board. */
13/** @brief I2C SCL pin used by the example board. */
15/** @brief I2C bus speed in hertz. */
16#define I2C_FREQ 400000UL
17/** @brief ICM-20948 I2C address selected by the AD0 pin. */
19/** @brief MCU pin connected to the IMU interrupt output. */
20#define PIN_INT D7 // ajusta a tu pin real
22/** @brief Global ICM-20948 driver instance. */
25/** @brief Print a separator line to Serial. */
26void printLinea() { Serial.println(F("------------------------------------------------------------")); }
27/** @brief Print a double separator line to Serial. */
28void printDobleLinea() { Serial.println(F("============================================================")); }
30/** @brief Interrupt pin electrical and latch configuration. */
31ICM20948_IntPinConfig pinCfg = {
41/** @brief Interrupt enable flags used by this example. */
42ICM20948_IntEnableConfig intEn = {
43 .rawDataRdyEn = 1 // inicializacion directa
46/** @brief Number of interrupt events observed by the ISR. */
47volatile uint32_t isrCount = 0;
50 * @brief Interrupt service routine for the IMU data-ready signal.
52void IRAM_ATTR isrHandler() {
57 * @brief Initialize I2C, verify the IMU, configure interrupts, and attach ISR.
63 Wire.begin(SDA_PIN, SCL_PIN);
65 if (!imu.beginI2C(ICM_ADDR, Wire, I2C_FREQ)) {
66 Serial.println(F("ERROR: beginI2C() failed."));
69 Serial.println(F("ICM-20948 ready."));
72 if (!imu.readWhoAmI(who) || who != 0xEA) {
73 Serial.println(F("ERROR: WHO_AM_I mismatch"));
76 Serial.printf("WHO_AM_I = 0x%02X\n", who);
78 if(!imu.intInit(pinCfg)){
79 Serial.println(F("ERROR: Initialization interruption failed"));
82 if(!imu.intEnableConfig(intEn)){
83 Serial.println(F("ERROR: Initialization interruption failed"));
87 attachInterrupt(digitalPinToInterrupt(PIN_INT), isrHandler, FALLING);
88 Serial.println(F("Interrupt configured. Waiting..."));
92 * @brief Report interrupt events when the ISR count changes.
95 static uint32_t lastCount = 0;
97 if (isrCount != lastCount) {
99 Serial.printf(">>> ISR disparada! Total: %lu\n", isrCount);