AVR Software UART

One of my favorite micro-controller chips is the ATTINY84. I has a variety of features and the small size (14 pins) makes it perfect for projects i create. One feature it lacks is a hardware UART. One way you can get around this is by using the USI as a hardware UART, but its only half duplex.

So in my searches i decided to use AVR305 and see if i could write a software UART, but i didn’t really feel like reinventing the wheel on this. So after much much much searching i finally found a pre written software UART.


The code is well done and simple to modify if necessary. The only thing i had to change was a reference to TIMSK to TIMSK0. If you are in doubt if this will work or if you have all the necessary items to make this lib work, just go into the header file and check the register attachments against the data sheet of the chip. If all match then you wont have an issue. If you find something that is not available or named different, just search for that functionality and change the name appropriately as i did above.

The lib contains test code that you can run to be sure everything is working properly. I connected a bluetooth module and paired it with my phone. Using BlueTerm i was able to send data to the controller and retrieve data from it.

As a side note this code should work with any ATTINY, ATMEGA, ect. Hopefully this post will help people find this info quicker in their future searches.

Also make sure you set the F_CPU for the chip you are using. If you do not it will use the wrong one and your timing will be off. I set mine up as a #define in main.c. Also the baud rate can be set in the header file.



This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.