I'm glad your getting things moving along, you should never have to clear the buffer, as long as your processing the data your receiving, whenever you read what you have received its removed from the rx buffer, also you shouldn't have to stop the rx interrupt, in fact unless you want to scan data as you receive it you shouldn't have to use it, mbed are fast, they can process much more data then serial can throw at them and still leave you plenty of cycles to do what you want,
I'm not sure why your rx interrupts stops firing, it shouldn't, is the mbed still running? not crashed, same goes for the transmitting unit,
in my SimpleSerialPacket library, (very alpha, not documented) I decided to leave everything I could out of interrupts so the flow of the program is predictable, the library is overkill for your situation and the overhead of the packets with checksums would be more then the data your sending or I would have mentioned it earlier, using the library I can read a serial data stream and decode it in about 10us, ofc the more data you through at it the longer it takes, but it never drops below 20,000 cycles a second and this is reading all 3 serial ports, (in my system gps, ahrs, and the control system)
what you need to do in your main loop is check if there is more than 5 bytes (4 digit ascii number and newline) in the MODSERIAL buffer, and read them, therefore clearing the buffer for more data, this could be accomplished with:
char str[10]={0,0,0,0,0,0,0,0,0,0};
while(1){
if(xbee.rxBufferGetCount() > 5)
xbee.scanf("%s/n", str);
}
}
you would need to send the data as 4 bytes and an /n so 0001/n ect,
the better solution would be to use example 2 in the MODSERIAL library, using autoDetectChar('/n') and the autodetect callback, MODSERIAL Example 2 although, again suitability all depends on the complexity of your protocol
Hello everyone, I'm trying to communicate between two robots each is equipped with an mbed and a connected xbee. the systems are completely symmetrical. my Xbee module is 4214-XBEE, flat antenna
This is the code for the sending robot
sending
Here is the code for the reading robot
Reading
My output is supposed to be abc. but it is only sometimes such. I'm getting: abbc, abcbc... etc Why am I getting so many errors? Is there anything wrong with my code? Is there any way to remove the errors?