0

I'm trying to call an interrupt routine (let's call it handler() ) every second on my arduino DUE. I thought the simplest way to do this was to use this library but it seems that i don't know how to use it...

results

my code

  • 1
    I guess you mean start(1000000). – Edgar Bonet Feb 19 at 11:26
  • yep............... this is embarassing ahahah Do you have a guess on why wasn't it working with start(1000) ? is Serial.print too long to execute ? – Julie96 Feb 19 at 13:31
  • 1
    Serial print in an ISR is not recommended. Set a flag in the ISR and poll in the loop() instead. – Mikael Patel Feb 19 at 13:32
2

You are trying to print 6 characters ("test\r\n"), i.e. 60 bits including the start and stop bits, 1000 times per second. This requires a baud rate of at least 60 kbit/s, yet the serial port has been configured for only 9.6 kbit/s. Something has to give...

As Mikael Patel wrote in a comment, it is generally inadvisable to Serial.print() from within an ISR. It is supposed to work, though, as long as you don't fill the Serial output buffer. The problem is that your code does fill the buffer, as it is writing to it faster than the UART can empty it. Once the buffer is full, the program will malfunction.

  • thank you ! I will definitly use a flag now – Julie96 Feb 20 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.