USART, Universally

The USARTs have lots of flexibility, so how do I present it? I’ve been mulling over it and decided to do one basic example program and then vary the protocol for additional examples.

I’ll be using two of the USARTs to communicate with each other. One, call it the primary USART, will send a string of characters to the second USART, the the second USART will send the same string back to the first.

The first example Normal Asynchronous Operation will echo the characters back immediately as they arrive. ISRs will be used for transmit and receive of each USART, circular buffers will be used, and the main function (loop) will just read from and write to the buffers as required. This is the most likely method the USARTs would be used, and is, in fact, the only method supported by the Arduino library.

The second example Synchronous Operation adds the clock signal so transfers are synchronous. This is a really straightforward switch.

The third example Half Duplex Operation uses one wire mode (a single wire for both directions. A full text line is sent from the first USART to the second, then the direction reverses and the text line is sent back to the first USART. This is a bit more complicated. Operation in RS-485 mode can’t be readily demonstrated without additional circuitry (TTL – RS-485 converters) and we only have one USART that brings out the XDIR direction signal needed by the converters. Of course the direction change can be done in software.

The fourth example SPI Operation only uses one USART, which is run in SPI master mode. I’ll probably base this one off of the SPI module slave example.

I might also add an example demonstrating auto-baud, a new feature that I should be able to demonstrate. I’ll see how much I can get done.

On another level, I “compiled” (a Scrivener term) the book to date in both PDF, for print, and MOBI, for Amazon EPUB, formats. and at least I’m impressed. It looks like it will come in at about a third the length of Far Inside The Arduino which considering it’s just a supplement for the ATmega4809 seems about right to me.