Arduino Serial Performance

With a view to maximising the available processor power (cycles) available for further enhancements of the algorithms used in ArduPilot I am always on the look out for ways to improve the efficiency of the code.

Unfortunately the standard Arduino software to support the serial output, which is used for diagnostics output and communication to the Ground Station, does not include a buffer.  Thus each time that the code makes a call to Serial.print() it does not return until the full string has been transmitted (well strictly until the last character has been loaded into the transmit register) at whatever serial baud rate is in use. e.g. output of 40 characters at 38400baud takes around 10mS.

 

This 'delay' is quite a significant amount of time when trying to achieve an update cycle of only 20mS, which is required in order to make use of every frame of data from the Remote Control.

 

I came across some code which implements a serial transmit buffer (as well as refining the existing serial receive code) in an alternative version of the HardwareSerial.h and HardwareSerial.cpp, by Kiril available from:
Arduino Forum > Software > Development, at
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?board=dev
Search for "Improved HardwareSerial" and use these new files to replace those in hardware/arduino/cores/arduino

There should be enough memory on the ATMEGA328 to increase the buffer sizes too.  These are defined in HardwareSerial.h:
#define USART_RX_BUFFER_SIZE  (64)

#derine USART_TX_BUFFER_SIZE  (64)

Has anyone else tried this - it seems good to me (but I've not put anything up in the air yet!), or does anyone know of any other implementations.  I just checked the new Arduino-0018 release and it doesn't appear to have incorporated any of these improvements.

 

 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Bump, Bump, anyone working on this yet? anyone else feel it could be useful?
  • Admin
    Christopher,

    Nice find. Maybe Jason Short can make use of it in the Ardupilot 2.5 code that is being built/tested?

    Regards,
    TCIII
This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…