Monday, February 22, 2010

A Full-Duplex Software UART

I recently was working on a small embedded project in which I had used an ATtiny48 microcontroller. While ATtiny48 had a whole lot of features, it didn't have a hardware UART interface and I didn't want to go for a higher priced ones only for a serial connection; So after a bit of googling, I found Half Duplex Interrupt Driven Software UART and Half Duplex Compact Software UART from Atmel website.

The interrupt driven version was written in C and I guess could be used after a little modification to compile it with GCC on GNU/Linux. Meanwhile, the code wasn't complex, So I decided to write one that provide a full duplex interface and compiles happily on my setup.

Well, I have tested it for my own very specific application and it has worked. Please don't assume it will for you. Also, since it uses a 8 bit timer, it will fail if you have a large atomic (a block of code in which global interrupt flag is unset). Also note that I have only tuned it for a 38400 bitrate on internal 8MHz RC oscillator but it should be fairly easy to change it for other speeds.

You can download the code from googlecode repository:
svn checkout http://masood.googlecode.com/svn/trunk/vuart/ 

Links:
AVR304: Half Duplex Interrupt Driven Software UART on tinyAVR and megaAVR devices
AVR305: Half Duplex Compact Software UART on tinyAVR and megaAVR devices
Code for AVR304
Code for AVR305

2 comments:

  1. Thanks for this - I used this successfully in my project to add a second UART to an ATMEGA88. I also added a RingBuffer to allow some buffering of the data. It works really well.

    ReplyDelete