DevLab_ICM20948 1.0.2
ICM-20948 9-Axis Motion Sensor Driver
Loading...
Searching...
No Matches
interrupt.ino
Go to the documentation of this file.
1/**
2 * @file interrupt.ino
3 * @brief I2C interrupt example for the DevLab ICM-20948.
4 * @author Jonathan Mejorado Lopez
5 * @details Configures the IMU raw-data-ready interrupt pin and counts ISR
6 * events on an Arduino-compatible board.
7 */
8
9#include <Wire.h>
10#include <DevLab_ICM20948.h>
11
12/** @brief I2C SDA pin used by the example board. */
13#define SDA_PIN 6
14/** @brief I2C SCL pin used by the example board. */
15#define SCL_PIN 7
16/** @brief I2C bus speed in hertz. */
17#define I2C_FREQ 400000UL
18/** @brief ICM-20948 I2C address selected by the AD0 pin. */
19#define ICM_ADDR 0x69
20/** @brief MCU pin connected to the IMU interrupt output. */
21#define PIN_INT D7 // ajusta a tu pin real
22
23/** @brief Global ICM-20948 driver instance. */
25
26/** @brief Print a separator line to Serial. */
27void printLinea() { Serial.println(F("------------------------------------------------------------")); }
28/** @brief Print a double separator line to Serial. */
29void printDobleLinea() { Serial.println(F("============================================================")); }
30
31/** @brief Interrupt pin electrical and latch configuration. */
33 .activeLevel = 1,
34 .driveMode = 0,
35 .latchMode = 0,
36 .clearMode = 1,
37 .fsyncActLevel = 0,
38 .fsyncIntEn = 0,
39 .bypassEn = 0
40};
41
42/** @brief Interrupt enable flags used by this example. */
44 .rawDataRdyEn = 1 // inicializacion directa
45};
46
47/** @brief Number of interrupt events observed by the ISR. */
48volatile uint32_t isrCount = 0;
49
50/**
51 * @brief Interrupt service routine for the IMU data-ready signal.
52 */
53void IRAM_ATTR isrHandler() {
54 isrCount++;
55}
56
57/**
58 * @brief Initialize I2C, verify the IMU, configure interrupts, and attach ISR.
59 */
60void setup() {
61 Serial.begin(115200);
62 delay(200);
63
64 Wire.begin(SDA_PIN, SCL_PIN);
65
66 if (!imu.beginI2C(ICM_ADDR, Wire, I2C_FREQ)) {
67 Serial.println(F("ERROR: beginI2C() failed."));
68 while (1) delay(200);
69 }
70 Serial.println(F("ICM-20948 ready."));
71
72 uint8_t who;
73 if (!imu.readWhoAmI(who) || who != 0xEA) {
74 Serial.println(F("ERROR: WHO_AM_I mismatch"));
75 while (1) delay(200);
76 }
77 Serial.printf("WHO_AM_I = 0x%02X\n", who);
78
79 if(!imu.intInit(pinCfg)){
80 Serial.println(F("ERROR: Initialization interruption failed"));
81 while(1) delay(200);
82 }; // nombre correcto
84 Serial.println(F("ERROR: Initialization interruption failed"));
85 while(1) delay(200);
86 }
87
88 attachInterrupt(digitalPinToInterrupt(PIN_INT), isrHandler, FALLING);
89 Serial.println(F("Interrupt configured. Waiting..."));
90}
91
92/**
93 * @brief Report interrupt events when the ISR count changes.
94 */
95void loop() {
96 static uint32_t lastCount = 0;
97
98 if (isrCount != lastCount) {
99 lastCount = isrCount;
100 Serial.printf(">>> ISR disparada! Total: %lu\n", isrCount);
101 }
102}
bool intEnableConfig(const ICM20948_IntEnableConfig &cfg)
bool readWhoAmI(uint8_t &whoAmI)
bool beginI2C(uint8_t address=0x69, TwoWire &i2cPort=Wire, uint32_t i2cSpeed=400000)
bool intInit(const ICM20948_IntPinConfig &cfg)
#define SCL_PIN
I2C SCL pin used by the example board.
Definition interrupt.ino:15
ICM20948_IntEnableConfig intEn
Interrupt enable flags used by this example.
Definition interrupt.ino:43
void printDobleLinea()
Print a double separator line to Serial.
Definition interrupt.ino:29
void setup()
Initialize I2C, verify the IMU, configure interrupts, and attach ISR.
Definition interrupt.ino:60
#define SDA_PIN
I2C SDA pin used by the example board.
Definition interrupt.ino:13
void printLinea()
Print a separator line to Serial.
Definition interrupt.ino:27
#define I2C_FREQ
I2C bus speed in hertz.
Definition interrupt.ino:17
#define ICM_ADDR
ICM-20948 I2C address selected by the AD0 pin.
Definition interrupt.ino:19
DevLab_ICM20948 imu
Global ICM-20948 driver instance.
Definition interrupt.ino:24
#define PIN_INT
MCU pin connected to the IMU interrupt output.
Definition interrupt.ino:21
void IRAM_ATTR isrHandler()
Interrupt service routine for the IMU data-ready signal.
Definition interrupt.ino:53
volatile uint32_t isrCount
Number of interrupt events observed by the ISR.
Definition interrupt.ino:48
ICM20948_IntPinConfig pinCfg
Interrupt pin electrical and latch configuration.
Definition interrupt.ino:32
void loop()
Report interrupt events when the ISR count changes.
Definition interrupt.ino:95