read() in interrupt?

Posted by Jens on Thu 04 Dec 2014 08:58 AM — 5 posts, 22,086 views.

#0
Hi
I've read on one of your other threads http://www.gammon.com.au/forum/?id=11488, that I shouldn't "try to do serial reading." in an ISR. I wanted to read some sensor values in a timer interrupt on an Arduino Mega2560, but encountered some serious issues doing so. The code/Arduino simply stops. I've now tried to do a workaround using some flags for the ISR and then implemented my main() as a state machine, but I would really like to know why I can't read in the ISR. I looked into the HardwareSerial class, and to me it looks like the read() function is only returning the data that is already in the rx buffer - I don't see it using any interrupts?
I hope someone can clarify why I can't get this to work the way I want it to :)

Best regards
Jens
USA Global Moderator #1
Nick is probably going to ask you to post in the arduino forums. :)

Template:Arduino
Please post Arduino-related questions to the Arduino Forum or to StackExchange: Arduino. This saves splitting questions and answers between this forum and the Arduino ones.
#2
The thread I linked is from this forum and it describes interrupts on Arduino, so I hope you/he can/will help me :)
USA Global Moderator #3
I understand, and yet...

The Microprocessors section of the forum is just a place where Nick can post interesting writeups about projects he's working on. It's set to Administrator posting only to try and prevent people from asking questions here instead of the arduino.cc forum.

The top of the page at http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123 says "Please post questions about electronics on the The Arduino Forum"

And if you search the forum for "Please post Arduino-related questions to the Arduino Forum" you'll find that all Arduino questions get the same instruction. ( https://www.google.com/search?q=%22Please+post+Arduino-related+questions+to+the+Arduino+Forum%22&btnG=Google+Search&domains=www.gammon.com.au&sitesearch=www.gammon.com.au&gws_rd=ssl )
Amended on Thu 04 Dec 2014 05:52 PM by Fiendish
Australia Forum Administrator #4
Jens said:

The thread I linked is from this forum and it describes interrupts on Arduino, so I hope you/he can/will help me :)


And I'm hoping you will post your question on the Arduino forum. I do not want to start a competing Arduino-related forum here (especially as the current one is a bit flaky, and I bet this would get quite a bit of traffic).

Please post your question on the Arduino forum in the Programming Questions section, and to save me asking you there to do it, post the code in question, inside code tags.