Missing a UART peripheral for your ATtiny? Well, “Nerd Ralph” has written a small software serial UART which can share a single pin for Rx & Tx when a simple external circuit is used.
“When the TTL serial adapter is not transmitting, the voltage from the Tx pin keeps Q1 turned on, and the AVR pin (Tx/Rx) will sense a high voltage, indicating idle state,” Ralph explained in a recent blog post. ”When the AVR transmits a 0, with Q1 on, Rx will get pulled low indicating a 0. R1 ensures current flow through the base of Q1 is kept below 1mA. When the AVR transmits a 1, Rx will no longer be pulled low, and Rx will return to high state. When the serial adapter is transmitting a 0, D1 will allow it to pull the AVR pin low. With no base current, Q1 will be turned off, and the Rx line on the serial adapter will be disconnected from the transmission.”
Ralph wrote the serial code to work as an Arduino library. When compiled, it utilizes just 62 bytes of flash and does not require any RAM, as there is no buffering. Since the code is written in AVR Assembly, it supports uber-high baud rates (up to 460.8kbps at 16Mhz).
“The default baud rate of 115.2kbps is defined in BasicSerial3.h, and can be changed with the BAUD_RATE define,” added Ralph. “The library defaults to use PB5 for both Tx and Rx. It can be changed with the UART_Tx and UART_Rx defines in BasicSerial3.S.”
Interested in learning more about the half duplex UART ATtiny software hack? You can check out an example sketch here, and HackADay’s coverage here.
Excellent, keep them coming! BTW, waiting for http://avrfeaks.net to shine as promised 😛 .