This module provides buffered, software-based, transmit-only UART functionality. TIMER0 is the baud-rate generator. By default, this module twiddles PORTEbit 1 or PORTDbit 1. By redefining a couple of functions you can make any output bit the transmit line.
To use the transmit-only UART functions, place this include in your source file:
For example, to simulate a 9600 baud UART transmission line on an ATmega103 running at 4 MHz, call tx_only_init() like this:
tx_only_init(0x02, 4000000 / 8 / 9600);
This function clears the transmit buffer.
If there is room in the transmit buffer, this function places the given character, c, into the transmit buffer and the function then returns true. Otherwise, it returns false.
If there is room in the transmit buffer, this function places the given string, str, into the transmit buffer and returns true. Otherwise, it returns false.
This function is analogous to tx_only_str(), except that instead of taking a string in RAM, str points to a string stored in the program space.
These two functions are provided by the programmer to twiddle the bits of the transmission line. The “low” and “high” that appear in their names are in reference to the signal level, where “low” means a negative voltage, and “high” means a positive voltage.
As written, this module has many limitations:
It supports only one UART.
It is hard-coded to use TIMER0.
All of the functions are linked into the image, even if they’re not used.
Because the interrupt service routine calls two possibly user-defined functions, it is especially slow.