When I looked at the header file of the Arduino library in Spresense, it was defined as follows:
void attachTimerInterrupt(unsigned int(*isr)(void), unsigned intus);
// Parameter:
// isr:the function to call when the timer interrupt occurred.
// This function must return the next timer period [microseconds].
// If this function returns 0, the timer stops and it has been as one shot timer.
// us —microseconds.
// The maximum value is about 26 seconds and if it exceeds, an error occurred.
// Note:
// This can not be used at the same time with tone().
It's a little hard to understand how to handle the return value of the callback function, but when I wrote the following code, it somehow worked.
#define INTERVAL 100
static unsigned long counter = 0;
unsigned int callback_func(){
Serial.print("callback_funcalled");
Serial.print(++counter);
Serial.println("times");
return INTERVAL;
}
void setup() {
Serial.begin (115200);
attachTimerInterrupt(callback_func, INTERVAL);
}
void loop() {
}
That's all for your information.
Thank you for your hard work.
It seems that samples are not rolled on the Internet.
attachInterrupt
Then, there are many, so please refer to them.
Perhaps you are not familiar with ISRs.
© 2024 OneMinuteCode. All rights reserved.