Pages: [1]   Go Down
Author Topic: Reliable UART between Arduino and Bluetooth Module for Large Data  (Read 1303 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all,

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.

Thanks all,
Aakash
« Last Edit: December 02, 2012, 11:03:40 pm by Aakash » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul5,

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?

Thanks again,
Aakash
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just an update: I've tested a ~1000 byte TX/RX @ 9600 bps and it worked perfectly. So your comment was correct Paul5. Thank you smiley
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8589
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I shouldn't worry about any buffer overruns or anything of the sort?
Correct, if doing nothing else the Arduino will eat those characters for breakfast and be looking around for something else to do.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: