-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Milestone
Description
I'm new about Pico SDK, so I'm just experimenting the APIs... I don't understand why this piece of code doesn't print triggered, unless I decomment sleep_ms(1). It seems the interrupt never triggers.
Reading the docs, the alarm_callback runs in IRQ context, so I don't need to insert sleep_ms(1). Moreover, in the example, in the alarm_callback there is a printf... Is it safe calling a printf in an IRQ routine?
If I'm missing something, let me know please.
I'm using RP2350 and SDK v2.1.0.
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/timer.h"
const absolute_time_t period = 1000000;
volatile bool irqTriggered;
absolute_time_t tim = 1000000;
int64_t alarm_callback(alarm_id_t id, void *user_data) {
irqTriggered = true;
tim += period;
add_alarm_at(tim, alarm_callback, NULL, false);
return 0;
}
int main()
{
stdio_init_all();
irqTriggered = false;
add_alarm_at(tim, alarm_callback, NULL, false);
while (true) {
//sleep_ms(1);
if(irqTriggered){
irqTriggered = false;
printf("triggered\n");
}
}
}Metadata
Metadata
Assignees
Labels
No labels