I'm working on a project that uses a Bluetooth module connected via UART to an Arduino Pro (m328p @ 8MHz/3.3V).
The devices that will be connecting to the Bluetooth module will be communicating via well formed packets (headers with packet size, check sum, etc). The devices will typically send packets in sizes from a couple of bytes all the way up to ~200 bytes. Even bigger in some cases. From my understanding, the UART buffer is only 64 bytes on the Arduino, and there is also no flow control.
The Arduino can send out large data packets fine (I've tested <100 byte sized strings). Though, incomming data packets is what I'm concerned about. Right now the module is running at 115200 bps, and I'm worried that some byte loss might occur between the Arduino and module. If I lower the bit rate to 9600 bps (the lowest I can select for the module I'm using), would this issue be averted?
An additional note: I'm planning on using the serialEvent() interrupt to drain the incomming byte buffer by storing the packet data bytes into a byte array in the RAM as soon as they're received. Then doing any logic afterwards.
Right now the module is running at 115200 bps, and I'm worried that some byte loss might occur between the Arduino and module. If I lower the bit rate to 9600 bps (the lowest I can select for the module I'm using), would this issue be averted?
The potential for serial buffer overrun has far more to do with what the Arduino is doing while it is not reading serial data. The Arduino can read data orders of magnitude faster than it can receive data, even at 115200.
An additional note: I'm planning on using the serialEvent() interrupt to drain the incomming byte buffer by storing the packet data bytes into a byte array in the RAM as soon as they're received. Then doing any logic afterwards.
The serialEvent() method is NOT an interrupt. It is simply a convenience function called after each execution of loop, to allow you to move the reading of serial data out of loop(). It does not interrupt loop() when serial data arrives.
You need to talk more about what this mysterious "logic" is. It, apparently, will be what influences how fast you can deal with serial data.
Thanks for your response. The Arduino will not be doing anything when data is received. The logic (communicating with I2C devices, SPI devices, etc) will be done after a full packet is received, and based on the contents of the packet. The Bluetooth devices will not send any more packets until a response is received from the Arduino, which will be after all other logic has completed.
Essentially, the loop() function will be running unimpeded when data is being received. Incoming data will stored into the RAM immediately.
So, if I understood what you said correctly, I shouldn't worry about any buffer overruns or anything of the sort?