Serial

The universal synchronous and asynchronous receiver and transmitter (USART) is an interface  type using two pins where one is used for transmitting (TX) and one for receiving (RX) the serial data between two devices, e.g. chips or units. Unlike the I2C (Wire) or SPI busses the serial interface can only be used between two devices. Typically the communication speed is from 1200 Baud to 115200 Baud but both lower and faster is also possible.

The RFzero board comes with the possibility of 5 serial devices, of which one is dedicated to the GPS module and the remaining 4 may be used for external connections.


Communicating via the serial interface

Here is an example that used both the Serial5 and USB interfaces by communicating between the them.

The above examples are rather simple. But what if you don’t want to process the received data before a terminating character is received, e.g. an exclamation mark (!). The below code is an example of how to do this using a buffer to store the USB data temporarily.

The above example uses a buffers 100 bytes in size. If a larger amount of data is expected a ring buffer, with start and stop positions, that is large enough to hold the received data should be used instead.

The last example shows how to receive data with the help of an Interrupt Service Routine (ISR). Please note the name of the ISR SERCOM#_Handler() where # is the SERCOM number and the IRQ handler Serial#IrqHandler() where the # is the Serial number. For SERCOM5 and Serial5 they are the same but all the others are different! Please see the SERCOM table at the top of this page.

Receiving USB data via an ISR is a complex task. Please see the USB generic example page how to do this in a different way using the Arduino standard function called yield().

Serial signalRFzero pinRFzero MCU pinArduino Zero/M0 pins
TXA4PA6A4
RXA5PA7A5

Don’t use serialEventRun()

You may see the use of the serialEventRun() function is many Arduino examples. However, we can’t recommend using it because it is part of loop() and thus may not get attention in slow loops and functions.

Instead use one of the other ways described. Then you are in control.