Ok, I found the problem.
First, I tried suggestions I got from the XIG group where I posted
something similar, that looked like incomplete responses from XIG.
Here is the conclusion I posted on this forum.
With suggestions I got there, I implemented RTS in the XBee library.
This reduced occurrence but problem still happened once in a while.
When it did, I could see the buffer fill up more than the maximum
number of bytes I was allowing to fill.
Then I increased baud rate between the xbee and the arduino from 9600
to 38400. This reduced occurrence some more.
I then realized I had a forgotten a "delay(1000)" somewhere in
my loop. So if a big response was coming in during that long delay,
the xbee was sending data through UART and my modified XBee library
with RTS support did not have a chance to stop incoming bytes (assert
(set High) RTS pin).
So I learned quite a lot in the process: RTS is a good thing
to understand, and long operations (delay(1000), for example) may
have
unwanted side effects.
Removing the delay makes the RTS less necessary, but I will recode
that support so it is more flexible, and will send a patch if this
could be useful in the library.
--
Claude