0

I have 2 XBee Serie 2 modules running ZigBee Pro (2007) connected on 2 differents Arduinos Unos.

Since Arduino Uno is Single Thread, I'm trying to use interrupts to pause the main function and do things aside when there's data received by the XBee module.

I tried to use the attachinterrupt function from Arduino and linking pin 2 (int0) to the Rx from the XBee Module But I don't have any interrupt, either from RISING state, DOWN state or FALLING state.

attachInterrupt(0, interruptXBee, RISING);

Am I doing it wrong by using the Rx pin, should I use another pin? (I've seen RTS/CTS pins but my payloads are smaller than the buffer so there's no useful way I can use those pins) .

Thank you!

Venix
  • 37
  • 6

1 Answers1

1

In a typical application, you'd let the serial port driver handle the serial interrupt, buffering the byte that comes in, and then in your main loop periodically check the buffer for data to process.

On embedded platforms with a single thread, I like to code each part of the program with tick() functions. Each tick does a little bit of work, remembers its state, and returns to the main thread. Depending on how responsive your program needs to be, you may want to limit the tick functions to 20ms to 100ms of work per call. Sometimes the tick will return immediately because it doesn't have anything to do.

In addition, you may have interrupt service routines that quickly service the interrupt, storing data in a place the next tick can find and process it.

So, in your case, you'd have an xbee_tick() that you're calling in your main loop. It looks for data in the serial receive buffer, processes it, and then returns to the main loop.

tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • Thanks for your comment. I wonder if the SoftwareSerial has this buffer allowing me to do that? – Venix Mar 22 '15 at 18:00
  • According to http://arduino.cc/en/Reference/SoftwareSerialOverflow, SoftwareSerial has a 64-byte buffer. – tomlogic Mar 22 '15 at 21:32