NittoBend双轴ADS传感器ESP32 Feather适配问题求助
Fixing ESP32 Feather + NittoBend Dual-Axis Sensor Interrupt WDT Timeout
Root Cause
The Interrupt wdt timeout on CPU1 error stems from two main issues:
- The original demo's interrupt service routine (ISR) likely includes blocking operations (like I2C reads or serial prints) that exceed ESP32's interrupt watchdog timer limits.
- The nDRDY pin (GPIO32) configuration is missing a pull-up resistor—since the sensor's nDRDY is an open-drain output, this can lead to unstable interrupt triggers or no triggers at all.
Step-by-Step Fixes
1. Correct Interrupt Pin Configuration
First, configure the nDRDY pin with a pull-up resistor to ensure stable signal detection:
#define NDRDY_PIN 32 #define NRST_PIN 15 void setup() { Serial.begin(115200); while(!Serial); // Reset pin setup pinMode(NRST_PIN, OUTPUT); digitalWrite(NRST_PIN, HIGH); // Sensor reset is active-low // nDRDY pin setup with pull-up (critical for open-drain output) pinMode(NDRDY_PIN, INPUT_PULLUP); // Attach interrupt to trigger on falling edge (nDRDY goes low when data is ready) attachInterrupt(digitalPinToInterrupt(NDRDY_PIN), dataReadyISR, FALLING); // Run your existing sensor initialization code here if(initTwoAxisADS()) { Serial.println("Two Axis ADS initialization succeeded"); } else { Serial.println("Initialization failed"); while(1); } }
2. Rewrite ISR to Be Non-Blocking
Replace the original heavy ads_data_callback with a minimal ISR that only sets a volatile flag. All data processing must happen in the main loop to avoid WDT timeouts:
volatile bool dataReady = false; // Minimal ISR - only set flag and exit void dataReadyISR() { dataReady = true; } void loop() { if(dataReady) { // Temporarily disable interrupt to prevent race conditions detachInterrupt(digitalPinToInterrupt(NDRDY_PIN)); // Read and process sensor data here (use your existing read logic) float xAngle, yAngle; if(readTwoAxisAngles(&xAngle, &yAngle)) { Serial.print("X Angle: "); Serial.print(xAngle); Serial.print(" | Y Angle: "); Serial.println(yAngle); } // Reset flag and re-enable interrupt dataReady = false; attachInterrupt(digitalPinToInterrupt(NDRDY_PIN), dataReadyISR, FALLING); } // Keep other main loop tasks short to avoid delaying interrupt handling }
3. Verify I2C Pin Mapping
Ensure your I2C initialization uses the correct pins for ESP32 Feather (default SDA=21, SCL=22). If using custom pins, explicitly initialize I2C:
Wire.begin(21, 22); // SDA pin, SCL pin
Critical Reminders
- Never run serial or I2C operations inside an ISR: These are blocking and will trigger WDT timeouts on ESP32.
- Volatile flag requirement: The
dataReadyvariable must be declaredvolatileto ensure the main loop detects updates from the ISR. - Interrupt re-enabling: Always re-enable the interrupt after processing data to catch the next ready signal.
内容的提问来源于stack exchange,提问作者user29732056
相关产品推荐
相关产品推荐

