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:
#include <tx-only.h>
This function initializes TIMER0 by placing it in the given mode, timer0_mode, and setting the counter value to timer0_count. Finally the OCIE0interrupt is enabled.
Only the three low-order bits of the timer0_mode argument are used. Register TCCR0is updated with these bits, plus bit CTC0. Register OCR0is updated with timer0_count.
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.
These functions are optional. If you don’t provide them, the library supplies its own version that twiddles PORTEbit 1 (or if the microcontroller does not have PORTE, then PORTDbit 1).
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.