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. */
24 DevLab_ICM20948 imu;
25
26/** @brief Print a separator line to Serial. */
27 void printLinea() { Serial.println(F("------------------------------------------------------------")); }
28/** @brief Print a double separator line to Serial. */
29 void printDobleLinea() { Serial.println(F("============================================================")); }
30
31/** @brief Interrupt pin electrical and latch configuration. */
32 ICM20948_IntPinConfig pinCfg = {
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. */
43 ICM20948_IntEnableConfig intEn = {
44 .rawDataRdyEn = 1 // inicializacion directa
45};
46
47/** @brief Number of interrupt events observed by the ISR. */
48 volatile uint32_t isrCount = 0;
49
50/**
51 * @brief Interrupt service routine for the IMU data-ready signal.
52 */
53 void IRAM_ATTR isrHandler() {
54 isrCount++;
55}
56
57/**
58 * @brief Initialize I2C, verify the IMU, configure interrupts, and attach ISR.
59 */
60 void 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
83 if(!imu.intEnableConfig(intEn)){
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 */
95 void 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}
DevLab_ICM20948.h
DevLab_ICM20948
Definition DevLab_ICM20948.h:173
DevLab_ICM20948::intEnableConfig
bool intEnableConfig(const ICM20948_IntEnableConfig &cfg)
Definition DevLab_ICM20948.cpp:1200
DevLab_ICM20948::readWhoAmI
bool readWhoAmI(uint8_t &whoAmI)
Definition DevLab_ICM20948.cpp:118
DevLab_ICM20948::beginI2C
bool beginI2C(uint8_t address=0x69, TwoWire &i2cPort=Wire, uint32_t i2cSpeed=400000)
Definition DevLab_ICM20948.cpp:6
DevLab_ICM20948::intInit
bool intInit(const ICM20948_IntPinConfig &cfg)
Definition DevLab_ICM20948.cpp:1176
SCL_PIN
#define SCL_PIN
I2C SCL pin used by the example board.
Definition interrupt.ino:15
intEn
ICM20948_IntEnableConfig intEn
Interrupt enable flags used by this example.
Definition interrupt.ino:43
printDobleLinea
void printDobleLinea()
Print a double separator line to Serial.
Definition interrupt.ino:29
setup
void setup()
Initialize I2C, verify the IMU, configure interrupts, and attach ISR.
Definition interrupt.ino:60
SDA_PIN
#define SDA_PIN
I2C SDA pin used by the example board.
Definition interrupt.ino:13
printLinea
void printLinea()
Print a separator line to Serial.
Definition interrupt.ino:27
I2C_FREQ
#define I2C_FREQ
I2C bus speed in hertz.
Definition interrupt.ino:17
ICM_ADDR
#define ICM_ADDR
ICM-20948 I2C address selected by the AD0 pin.
Definition interrupt.ino:19
imu
DevLab_ICM20948 imu
Global ICM-20948 driver instance.
Definition interrupt.ino:24
PIN_INT
#define PIN_INT
MCU pin connected to the IMU interrupt output.
Definition interrupt.ino:21
isrHandler
void IRAM_ATTR isrHandler()
Interrupt service routine for the IMU data-ready signal.
Definition interrupt.ino:53
isrCount
volatile uint32_t isrCount
Number of interrupt events observed by the ISR.
Definition interrupt.ino:48
pinCfg
ICM20948_IntPinConfig pinCfg
Interrupt pin electrical and latch configuration.
Definition interrupt.ino:32
loop
void loop()
Report interrupt events when the ISR count changes.
Definition interrupt.ino:95
ICM20948_IntEnableConfig
Definition DevLab_ICM20948.h:123
ICM20948_IntEnableConfig::rawDataRdyEn
uint8_t rawDataRdyEn
Definition DevLab_ICM20948.h:132
ICM20948_IntPinConfig
Definition DevLab_ICM20948.h:104
ICM20948_IntPinConfig::activeLevel
uint8_t activeLevel
Definition DevLab_ICM20948.h:105