Generic UART for Any Microcontroller

Summary of Generic UART for Any Microcontroller


This article describes implementing a custom UART protocol on microcontrollers lacking built-in ports. The author successfully created a simple application using the PIC18F4550 that accepts two-byte commands to toggle pins and echo responses. The system operates at 9600 baud without hardware flow control, utilizing software-defined transmit and receive pins alongside a ground connection.

Parts used in Generic UART for Any Microcontroller:

  • PIC18F4550 microcontroller
  • LATD1 pin
  • UART transmit pin
  • UART receive pin
  • Ground connection
  • USB-serial adapter
  • Minicom software

Communicating with a micro-controller at runtime, is a very useful
facility. It can be used for debugging, or to send commands etc. One of the easiest available protocol to communicate is UART. It requires a pin for transmit and a pin for receive, and the GROUND connection. There are many available programs that allow us to communicate using UART on the serial port, or using a usb-serial adapter. e.g. hyperterminal, minicom, etc.

Generic-UART-for-Any-Microcontroller
Generic-UART-for-Any-Microcontroller

However, not all microcontrollers have UART ports in built.

i was taking a look at the UART protocol, and it seemed pretty simple to implement. So i gave it a go, and was zapped when it just worked the first time :).

Here is a little app that accepts 2 byte commands. Toggles LATD1 when it receives the command “TG”, and echoes back the command after its done. Invert flag is provided. ( Inversion may be needed if we are not working directly with a real serial port). Tested with minicom @9600 baud, with hardware-flow-control OFF, so that it sends the chars we type.

It is tested on the PIC18F4550, will need modifications to run on other microcontrollers.

The code is attached.

Its also available as a module to include at https://github.com/manojmo/pic_micro

Source: Generic UART for Any Microcontroller

Quick Solutions to Questions related to Generic UART for Any Microcontroller:

  • What is the easiest available protocol to communicate with a micro-controller?
    UART is one of the easiest available protocols for communication.
  • How many pins are required for UART communication?
    UART requires a pin for transmit, a pin for receive, and a GROUND connection.
  • Can all microcontrollers have UART ports built-in?
    No, not all microcontrollers have UART ports built-in.
  • What command toggles the LATD1 pin in the described application?
    The command TG toggles the LATD1 pin when received.
  • At what baud rate was the application tested?
    The application was tested at 9600 baud.
  • Does the tested setup use hardware-flow-control?
    No, the test was conducted with hardware-flow-control OFF.
  • What program was used to test the UART implementation?
    Minicom was used to test the implementation.
  • Is the provided code directly compatible with all microcontrollers?
    No, modifications will be needed to run the code on other microcontrollers.
  • What does the application do after receiving a command?
    The application echoes back the command after it is done.
  • Where can the module source code be found?
    The source code is available as a module at https://github.com/manojmo/pic_micro.

About The Author

Muhammad Bilal

I am a highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.