Skip to content

User Adaptations

Michael Jonker edited this page Dec 7, 2015 · 6 revisions

There are several possibilities to tailor the Serial Object defintion:

  • The recommended way is to define your own configurations by adding a boards.txt file as explained below. This mechanism provides sufficient means to configure 99% of your needs.

  • In case the boards.txt file does not provide the full required flexibility you need, you can adapt a copy of the header file HardwareSerialRS485_configuration.h that you have to place in the /utility subfolder (to be created if not existing) of the same folder as where you copied the boards.txt file. In this case you should make sure that the ...cpp.extra_flags definitions in your boards.txt file contain the string "-I{runtime.platform.path}" (either directly or indirectly through the {RS485_flags}). This will ensure that your copy of the HardwareSerialRS485_configuration.h is in the include search paths.

  • Finally you could hack the HardwareSerialRS485_configuration.h version which is the folder libraries/HardwareSerialRS485/src/utility and adapt it to you needs. This may be the fastest way, but is not recommended: you will not profit from multiple board configuration options and installing a new release of the library will undo your changes.

Making your personal copy of the configuration files

You are advised to create the following nested folder structure in your project space:

<myArduinoProjectFolder>/hardware/HardwareSerialRS485/avr

where you should replace <myArduinoProjectFolder> with the name of your project folder, i.e. the folder where all your sketch folders are located as well as the libraries folder.

Then, copy into this folder the file boards.txt and the file DisableHardwareSerial.h. Both files can be found in the folder: <myArduinoProjectFolder>/libraries/HardwareSerialRS485/extras . The boards.txt file will have to be tailored to reflect your hardware situation as described below. The file DisableHardwareSerial.h should be copied as is and does not need further adaptation.

Adapting boards.txt

The boards.txt file can be adapted to define the c++ preprocessor macros that tailor the definition of your HardwareSerialRS485 classes. If no definitions are given, then the HardwareSerialRS485_configuration.h file provides proper default values as described above.

In the example boards.txt file that comes with the HardwareSerialRS485 library you will see the definition of two boards: Arduino UNO with RS485 and Arduino Micro with RS485. If you want to add other boards with RS485, then the examples should provide enough information to add this yourself. These boards will appear in the IDE under the Tools menu. In addition, the boards.txt file defines board sub-menus. After selecting a board defined in the boards.txt file you will see a new sub-menu item right below the selected board menu item.

The predefined choices here are RS485 and no RS485, but you can add as many configurations as you need (with different TxE, RxE* connections, buffer space parameters, etc.).

As mentioned earlier, the specification of the TxE and RxE* mapping to the output pins of the Atmega use the native form and not the Arduino convention. The mapping is different on the Atmega328p boards and the Atmega32u4. For your convenience, the file boards.txt contains a table of how these Pin numbers map to Port numbers.