Arduino + interrupt + xbee

Hey guys,

I'm having a bit of a problem. Currently Im trying to work with arduino and xbee and it's been working great.

Xbee is used in api mode, and thanks to the great arduino-xbee library getting it up and running wasn't to hard.

I was running the xbee receiving function from the main loop of the program (void loop()), but when I tried to put it in an interrupt the same code did not work. I found that the xbee library function readPacket( timeout ) could not work within the interrupt because it used millis() for the timeout.

Then I did a simple check within the interrupt function (triggering interrupt using attachInterrupt) if the serial was available. And it wasn't. Then I went on debugging, and I found something strange.

When I send a message to the arduino xbee, it triggers the interrupt. And i print the availability (so not available). When the interrupt ends, and he goes back into the main loop I print the serial availability as well and then it is available.

How is that possible??

Hope someone can help me with this problem.

Thanks in advance.

Gr.

I'm not fully versed in Interrupts, but from what i found out that let me know i couldn't do what i was trying to with interrupts may help you. Interrupts and serial data are tricky because when serial data comes in an OS interrupt is what puts that data into the buffer. Also only one interrupt can act at a time, i think your attached interrupt is acting before the OS interrupt is putting the data in the buffer. does that make sense?

another way: data comes in, your interrupt checks avalibility and then ends, the OS interrupt adds the data to the buffer then ends, and your program reads the buffer.

Again, not an expert, just a guy with enough information to be dangerous.

Nate