MAX30001G  1.2.0
Arduino library for MAX30001G ECG and BIOZ AFE
Interrupt Handling

The driver keeps default behavior in serviceAllInterrupts() (updates global flags), and also supports user callbacks. For IRQ-driven sketches, prefer servicePendingInterrupts() in loop().

Interrupt Usage

Wire MAX30001G INTB (and optional INT2B) to interrupt-capable GPIO pins and pass those pins to the constructor.

const uint8_t AFE_CS_PIN = 10;
const int AFE_INT1_PIN = 2; // INTB
const int AFE_INT2_PIN = -1; // INT2B optional, -1 if unused
MAX30001G afe(AFE_CS_PIN, AFE_INT1_PIN, AFE_INT2_PIN);
void setup() {
// Constructor attaches ISR handlers for valid interrupt pins.
// Choose which status events drive INT1/INT2:
afe.setInterrupt1(true, true, true, false, false); // ECG + BIOZ + RTOR on INT1
afe.setInterrupt2(false, false, false, false, false); // INT2 disabled
}
void loop() {
if (afe.servicePendingInterrupts()) {
// STATUS was serviced and global flags/callbacks are up to date.
}
}
MAX30001G device driver class used by Arduino sketches.
Definition: max30001g.h:34

servicePendingInterrupts() uses Arduino core APIs noInterrupts() and interrupts() to atomically read/clear the software pending flags. These APIs are available on AVR, SAMD, ESP8266, and ESP32 Arduino cores, so no API change is needed for ESP-type boards.

If your board does not wire interrupt pins, call serviceAllInterrupts() periodically instead. If you provide your own ISR, set library globals afe_irq_pending and afe_irq1_pending/afe_irq2_pending (do not use a separate local pending flag). If you use latched event/fault globals, clear them explicitly with clearLatchedStatusFlags() after handling.

Configure which events drive INT1/INT2

setInterrupt1(...) and setInterrupt2(...) program MAX30001G EN_INT1 and EN_INT2.

Example:

// INT1: ECG + BIOZ FIFO related interrupts
afe.setInterrupt1(true, true, false, false, false);
// INT2: R-to-R interrupt
afe.setInterrupt2(false, false, true, false, false);

Available per-event callbacks (<tt>InterruptEvent</tt>)

Example: Individual ECG and BIOZ FIFO callbacks

void onEcgFifo(MAX30001G* dev, uint32_t status, void* ctx) {
(void)status;
(void)ctx;
dev->handleECGFifoInterrupt(false); // pushes samples into global ECG_data
}
void onBiozFifo(MAX30001G* dev, uint32_t status, void* ctx) {
(void)status;
(void)ctx;
dev->handleBIOZFifoInterrupt(false); // pushes samples into global BIOZ_data
}
void setup() {
afe.setInterruptEventCallback(MAX30001G::IRQ_ECG_FIFO, onEcgFifo);
afe.setInterruptEventCallback(MAX30001G::IRQ_BIOZ_FIFO, onBiozFifo);
}
void handleECGFifoInterrupt(bool reportRaw=false)
Convenience callback handler: read ECG FIFO.
Definition: max30001g_interrupt.cpp:338
void handleBIOZFifoInterrupt(bool reportRaw=false)
Convenience callback handler: read BIOZ FIFO.
Definition: max30001g_interrupt.cpp:342
@ IRQ_ECG_FIFO
Definition: max30001g.h:51
@ IRQ_BIOZ_FIFO
Definition: max30001g.h:55
max30001_status_reg_t status
Definition: max30001g_globals.cpp:80

Example: One aggregate callback

void onAfeAggregate(MAX30001G* dev, uint32_t status, void* ctx) {
(void)ctx;
}
void setup() {
afe.setInterruptAggregateCallback(onAfeAggregate, nullptr, mask);
}
void handleRtoRInterrupt(void)
Convenience callback handler: read RTOR data.
Definition: max30001g_interrupt.cpp:346
#define MAX30001_STATUS_RRINT
Definition: max30001g_defs.h:73
#define MAX30001_STATUS_BINT
Definition: max30001g_defs.h:67
#define MAX30001_STATUS_EINT
Definition: max30001g_defs.h:63

If aggregate and individual callbacks are both registered, aggregate runs first.

Interrupt Callback API summary

  • setInterruptEventCallback(event, cb, context)
  • clearInterruptEventCallback(event)
  • setInterruptAggregateCallback(cb, context, statusMask)
  • clearInterruptAggregateCallback()
  • clearAllInterruptCallbacks()
  • clearLatchedStatusFlags()