Multiple serial with different baud speed on Mega2560


as anyone try to use multiple serial ports of Mega2560 at different baud speed ? I have 2 serial sensors connected (one at 115200bps, one at 4800bps), and a wireless network at 4800bps. The issue is that I get overflow on the 115200bps buffer whenever I write on the 4800bps wireless network. Which make totally sense because it takes 40ms to send a message and during 40ms there is 115200/(8N+1)*40e-3= 512bytes (>buffer_syze). I cannot change the speed of any of the devices. One option would be to write on the 4800bps wireless network one byte at a time, but if there is a more simple option. Also I'll have to read the 4800bps sensor so doing everything byte after byte seems to get me into few different loops with lot of condition to check no buffer is close to overflow. FastSerial library from AdruPilot-Mega with TX buffer look like an option, any advice.


FastSerial library from AdruPilot-Mega with TX buffer look like an option, any advice.

That probably would be a good thing to try, having sending not being a blocking function, but rather interrupt supported.

Also in addition you can look at increasing the rec buffer sizes if you have SRAM to spare. HardwareSerial.cpp file in the arduino core library is where they define the rec buffer size used, presently set to 128 bytes.


FastSerial is a good option when adjusting the size of rx and tx buffer for each port. I’m not done with all the parsing of data so hopefully it will still run fast enough not to lose any data.

I'm writing libraries for the sensors I am using. I'm struggling with the use of FastSerial inside these libraries. In my test sketch I use


to create the FastSerial port. But went I do:

MTi::MTi(uint8_t portNumber, long baud, unsigned int rxBuffer, unsigned int txBuffer) { FastSerialPort(mti_serial,port_number); }

for the constructor in MTi.cpp I get:

E:\local\arduino-0022\libraries\MTi\MTi.cpp:7: error: no matching function for call to 'FastSerial::FastSerial()' E:\local\arduino-0022\libraries\FastSerial/FastSerial.h:106: note: candidates are: FastSerial::FastSerial(uint8_t, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t) E:\local\arduino-0022\libraries\FastSerial/FastSerial.h:102: note: FastSerial::FastSerial(const FastSerial&) E:\local\arduino-0022\libraries\MTi\MTi.cpp:9: error: expected unqualified-id before string constant E:\local\arduino-0022\libraries\MTi\MTi.cpp:9: error: a function-definition is not allowed here before '{' token