Have you ever exchanged data between the Micro-controller and Computer ??

Reading Time: 5 minutes

Serial Communication, So let’s continue with the learning of Embedded Development. This is the third blog or session from the series I hope you have liked the previous content.

As the title of the blog describes. Today we are going to learn how we can exchange the data between the Micro-controller and Computer and this whole process will work under the serial communication protocol.


What is Serial Communication ??

In telecommunication and data transmission, serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels.

serial communication
  • Serial communication is an asynchronous type communication protocol where two devices exchange data serially so that is one bit at a time. They use two data lines to make this communication possible.
  • Serial Communication Protocol is asynchronous as neither of the data line carries a clock signal.
  • It allows duplex communication which means communication or the transfer of data is possible from A to B and B to A Simultaneously.

Why we are discussing Serial Communication protocol?

We are because we will be using this protocol to exchange data between the micro-controller and the computer where the data is sent in series i.e. one after the other then this communication protocol is known as Serial Communication Protocol.


How fast through this data can be transferred?

So the speed of this protocol to send data is known as baud Rate and quoted as bits per sec.
So common baud rates are 9600,38400,57600 and 115200 bps.


**the data rate will be lower because of processing time on the slower side of the communication (the micro-controller).

*So through serial communication, we can easily connect our micro-controller to our computer ?? No, it’s not that simple..!

Today’s pc / laptop does not support serial communication so we need a serial module that sits in between the two and provides a serial interface to the micro-controller and USB interface to your computer.


Let’s Connect them:

*Linux Users

if you have newer revisions of the discovery board then on connecting the microcontroller with pc you see the TTY device appear in /dev.

$ # Linux
$ dmesg | tail | grep -i tty
[13560.675310] cdc_acm 1-1.1:1.2: ttyACM0: USB ACM device
This is the USB <-> Serial device. On Linux, it’s named tty*

Note* If you are not able to see this device connection on your console then you might have the older version of the Board. So click on this connection for the older version board to set the connection for the older version Board. Let’s continue 🙂

Sending data to serial interface or Micro-controller using minicom.

We will not use echo instead we will be using minicom to interact with the serial device using the keyboard.

But first, we need to configure the minicom before using it.

Create a file in (home directory) ~/.minirc.dfl with the following contents:
$ cat ~/.minirc.dfl
pu baudrate 115200
pu bits 8
pu parity N
pu stopbits 1
pu rtscts No
pu xonxoff No
*Note make sure this file ends in a new line! Otherwise, minicom will fail to read it.
The next step is to launch minicom.
$ # NOTE you may need to use a different device here
$ minicom -D /dev/ttyACM0 -b 115200
This tells minicom to open the serial device at /dev/ttyACM0 and set its baud rate to 115200. A text-based user interface (TUI) will pop out as shown below.
screen

Now you can send data using keyboard TUI will not echo back but if you are using an external module then you can see a led blinking on each keystroke.
These are some commands to control the minicom.
//
Ctrl+A + Z. Minicom Command Summary
Ctrl+A + C. Clear the screen
Ctrl+A + X. Exit and reset
Ctrl+A + Q. Quit with no reset

//

NOTE Mac users: In the above commands, replace Ctrl+A with Meta.

**Win Users

Before connecting the board just run this command on the terminal.
$ mode
  1. It will show the number of devices connected to your system.
  2. The ones that start with COM in their name are serial devices.
  3. Take note of all the COM ports mode outputs before plugging the serial module.
  4. Now plug your discovery board and run the same command again and you will see a new COM port appear on the list so this is the COM port assigned to the serial functionality on the board.
Note**If you didn’t get a new COM port then you are on the older version of Board This is the link to configure that.
Now launch putty. A GUI will pop out.
screen 2

Then in the “Session” category, you need to open the “Serial” as the “Connection type“.
Next, pick the “Connection/Serial” and make sure about the following configuration of your serial port.
“Speed (baud)”: 115200
“Data bits”: 8
“Stop bits”: 1
“Parity”: None
“Flow control”: None
Finally, click the Open button. A console will show up now:

output screen
If you type on this console, the TX (red) LED on the Serial module should blink. Each keystroke should make the LED blink once.

So testing sending data is done, now we will test whether or not our micro-controller receives it or not.
This testing receiving data is useful in debugging process.
If you have a newer revision of the board you can set up a loopback by shorting the PC4 and PC5 pins using a female to female jumper wire, you can take help from here for the shorting.

*Now when you type something in putty or minicom you will also see whatever you typed is echoed back to the minicom/putty console.

For more Embedded related blogs visit https://blog.knoldus.com/discovery-board/

Reference is taken from https://docs.rust-embedded.org/discovery/10-serial-communication/index.html


If you want to read more content like this?  Subscribe to Rust Times Newsletter and receive insights and latest updates, bi-weekly, straight into your inbox. Subscribe to Rust Times Newsletter: https://bit.ly/2Vdlld7.

Written by 

Nitin is a Software Consultant, with experience of more than 7 months. He works on Rust Programming Language and Embedded Development using Rust. He is also fond of Java Programming & Artificial Intelligence. Apart from that, his hobbies are Watching Netflix, Reading, Singing & Writing.

1 thought on “Have you ever exchanged data between the Micro-controller and Computer ??7 min read

Comments are closed.