Just how fast are interrupts serviced on a Pico running the Arduino framework? Fast enough!
I sort of have the Arduino environment for the RP2040 setup in VSCode thanks to PlatformIO. But, not totally, just yet.
I made a basic sketch registering a falling edge interrupt on GPIO0 of the Pico:
#include <Arduino.h>
void blink();
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
pinMode(2, OUTPUT); // Toggle in ISR
pinMode(0,INPUT_PULLUP);
attachInterrupt(0, blink, FALLING );
gpio_pull_up(0);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
void blink() {
//Perform an atomic bitwise XOR on GPIO_OUT, i.e. GPIO_OUT ^= wdata
*(volatile uint32_t *)(SIO_BASE + 0x1c ) = 1<<2; // Toggle GPIO2
}
In the ISR I toggle GPIO2 using the atomic xor GPIO write register.
I measured the interrupt latency to be approximately 1.5 us:
With just an empty task loop, the ISR jitter was approximately 50 ns:
The maximum continuous interrupt frequency appears to be 150 kHz. Beyond 150 kHz the Pico can't keep up:
I think this is more than adequate to service a I2C/SPI sensor interrupt.