Asynchronous Serial is serial communication without a dedicated clock line (which is why it is not synchronous). It is generally just known as Serial (and other serial protocols are known by other names, like I2C or SPI). It is fairly standard in protocol, but can be found at multiple voltage levels. On microcontrollers, the hardware to speak serial is known as a UART (Universal Asynchronous Receiver-Transmitter) or USART (Universal Synchronous-Asynchronous Receiver-Transmitter). This can also be implemented in software, but it is usually only capable of lower speeds.
Serial is not a bus, and is designed to just be point to point. However, bidirectional communication may not be necessary, and it is sometimes possible to have a single transmitter drive multiple receivers. Just don't have multiple transmitters try to drive the same receiver (the transmitters will damage each other).
- RS232: Computer serial ports (9 pin cables). 12V signaling
- TTL: 5V signaling
- CMOS: 3.3V signaling
Each message is broken down into chunks, usually of a byte in size. These chunks have bits added onto them to enable the protocol to function, and detect when bits are being sent or not.
Each chunk will have 1 start bit. There is usually 1 or 2 stop bits. There may be a parity bit. There are usually 8 data bits (one classical byte) in each chunk, but there may be other values (5-9). The most common combination (that you can probably assume you are interfacing with for most devices) is 8 data bits, 0 parity bits, and 1 stop bit. This is usually written as 8-N-1 (the N stands for No Parity). If you do not have these setting correct, your devices will not be able to talk. If you are getting garbage, these settings may be incorrect.
The baud rate is the number of symbols that can be driven onto the wire and detected per second. Depending on the system being used, there may be more or less than a bit of data for each symbol. For Serial, each symbol carries one bit. However, the baud rate is not the exact rate of useful data you can transfer. Because of the start, stop, and parity bits, your data rate is actually somewhat slower. For the normal configuration of 8-N-1, you get 8 data bits for every 11 symbols. Below is a table of common baud rates, and the data bit rate (using 8-N-1). Both devices must use the same baud rate or they will be unable to talk. If you are getting garbage, the baud rate may be incorrect. 9600 is the most common default, although if you are doing serial between two fast devices, you can set them to 115200 (which is the fastest). You usually want to go as fast as possible, within the limits that both devices support. Note that these are theoretical max speeds, and you are lightly to get a little less in actual use.
|Baud Rate||Bit Rate at 8-N-1||Bytes (characters) per second|
Arduino IDE (Windows/Linux/Mac)¶
Here is some code to get you started with serial for various platforms.