Serial communication

Serial communication - 图1

This is what we’ll be using. I hope your laptop has one!

Nah, don’t worry. This connector, the DE-9, went out of fashion on PCs quite some time ago; it gotreplaced by the Universal Serial Bus (USB). We won’t be dealing with the DE-9 connector itself butwith the communication protocol that this cable is/was usually used for.

So what’s this serial communication? It’s an asynchronous communication protocol where twodevices exchange data serially, as in one bit at a time, using two data lines (plus a commonground). The protocol is asynchronous in the sense that neither of the shared lines carries a clocksignal. Instead both parties must agree on how fast data will be sent along the wire before thecommunication occurs. This protocol allows duplex communication as data can be sent from A to Band from B to A simultaneously.

We’ll be using this protocol to exchange data between the microcontroller and your laptop. Incontrast to the ITM protocol we have used before, with the serial communication protocol you cansend data from your laptop to the microcontroller.

The next practical question you probably want to ask is: How fast can we send data through thisprotocol?

This protocol works with frames. Each frame has one start bit, 5 to 9 bits of payload (data) and 1to 2 stop bits. The speed of the protocol is known as baud rate and it’s quoted in bits persecond (bps). Common baud rates are: 9600, 19200, 38400, 57600 and 115200 bps.

To actually answer the question: With a common configuration of 1 start bit, 8 bits of data, 1stop bit and a baud rate of 115200 bps one can, in theory, send 11,520 frames per second. Since eachone frame carries a byte of data that results in a data rate of 11.52 KB/s. In practice, the datarate will probably be lower because of processing times on the slower side of the communication (themicrocontroller).

Today’s laptops/PCs don’t support the serial communication protocol. So you can’t directly connectyour laptop to the microcontroller. But that’s where the serial module comes in. This module willsit between the two and expose a serial interface to the microcontroller and an USB interface toyour laptop. The microcontroller will see your laptop as another serial device and your laptopwill see the microcontroller as a virtual serial device.

Now, let’s get familiar with the serial module and the serial communication tools that your OSoffers. Pick a route: