ATMEGA4809 support 4 serial ports

Hello together,

I grabbed from the data sheet of ATMEGA4809 which is used in Nano Every, that the MCU support 4 serial ports. On the every board there are only 2 in use (1 for the USB (Serial) and one that can be used freely (Serial1)).

For my application I need another Serial port. I made some test with the SoftSerial-Library, but it seem that this is not fast and/or reliable enough for my application.

Now that I read that (in theory) there are 4 serial port available on ATMEGA4809, I would like to asked the question if there is a way to access the additional ones?

Thanks for your ideas
A.

The four USARTs are:

  • USART0 - Not described in Arduino documentation, this uses D2 for TXD, D7 for RXD, A4 for XCK, and A5 for XDIR. This is the only USART with full signals directly available on the board.
  • USART1 - This is device Serial1 in the Arduino library and uses D1 for TXD, D0 for RXD, and has XCK available on D4. This uses alternate pins which must be set in the port multiplexer. PORTMUX.USARTROUTEA |= PORTMUX_USART1_ALT1_gc.
  • USART2 - Not described in Arduino documentation, this uses D6 for TXD and D3 for RXD. Alternate pins are used which must be set in the port multiplexer. PORTMUX.USARTROUTEA |= PORTMUX_USART2_ALT1_gc.
  • USART3 - Connects to the USB interface and is device Serial in the Arduino library. Signals not brought out on the board.

So basically it's USART0 and USART2 that you can use that the library doesn't support off the shelf. There is code dangling around in the library core that might be possible to enable. I haven't tried it. It looks like it can be accomplished by adding lines to nona4809/pins_arduino.h for HWSERIAL2 (USART0) and HWSERIAL3 (USART2) following what was done for HWSERIAL1 and HWSERIAL0. I always access the ports directly.

1 Like

Thanks Almytom.
This was exactly what I was looking for. I will now dig into the header and stuff to get that running.
When your say "I always access the ports directly", I assume that you are not counting on the Serial-library but on a direct access to the serial port for reading and writing to get a better performance.
In my application the NANO is coordinating the communication between two devices. And I am expecting to receive about 1kB/sec from one device and 256B/sec from the other device - of cause asynchronous. And after checking the content the information has to be forwarded to the other device. Due to that I have already manipulated the reception buffer, which of cause is taking most of the available memory now. I am thinking to write my own buffer routines to get everything faster and more control on the memory.
"I always access the ports directly" do you have any code sniple to show how to directly read and write to the serial ports, which I can use as a base ... if it is in your book, just let me know ...

Digging more deeply in this forum I found the solution mentioned by Almytom here:
https://forum.arduino.cc/index.php?topic=639740.0

Looking at that link, that's certainly what needs to be done. My Far Inside The Arduino book is pretty extensive on how to use the USART directly on a ATmega328P based Arduino board. Far Inside The Arduino: Nano Every Supplement is a supplement specific for the ATmega4809. The latter has example programs with some details, but not the basics of UART operation. They are all interrupt driven with FIFOs for buffering. They communicate between two ports on a single Nano Every (USART0 and USART1). Examples include conventional asynchronous operation, synchronous operation, half duplex (1-wire) operation, RS-485 (differential, half-duplex) operation and Master SPI operation. Only asynchronous is supported in the Arduino library. Available in print and Kindle ebook on Amazon.

You get access to all four serial port and much more by using MegaCoreX.