AVR Software UART Tx
AVR UART Tx in software for ATtiny series
AVR, UART, Software, Communication, ATtiny, Assembly, avr-asm--by Captdam @ 2022-10-23 07:41 GMT
Why software UART Tx
Recently I was working on a project using ATtiny series MCU. The ATtiny series MCU has smaller footprint than ATmega series MCU, making it favored for small applications. However, the ATtiny series MCU lacks the hardware communication modules. An USI module is used as a half-software half-hardware solution for SPI or I2C communication. For UART, there is no hardware UART support on ATtiny series (atleast for all ATtiny in PDIP package), except the ATtiny 2313 MCU.
For my application, using a ATmege MCU is not an option, because it is too big for my PCB. Using the new core-idependent AVR is not possible due to lack of programer. Therefore, I have to come with a software UART solotion.
Fast UART Tx
For some application, only transmitter is required. The MCU acts like a beacon device, it only sends data to external device but does not receive data from external device.
- Acknowledgement is not required in this situation, because the beacon device sends the signal no matter a receiver is presented.
- In case of communication error, the receiver will discard the error data and wait for next data. The receiver should not request the sender to resend the data. The data is out-of-date by the time the sender resends the data.
The project I was working on requiring the ATtiny45 MCU to periodically sending data to a RPI using UART at very high speed, at 500k BAUD. To satisfy the timing requirement, I have to code the software UART in assembly code.
It is worth to mention, if using the internal RC clock, the clock must be calibrated at the working voltage because the clock frequency directly contributes the BAUD.
Here is the code. The
softuart_f16_* version is used for 16MHz or 8MHz CPU and it sends data at 1M BAUD and 500k BAUD respectively. The
softuart_f10_* version is used for 20MHz or 10MHz CPU and it sends data at 1M BAUD and 500k BAUD respectively. The only difference between these two versions is the number of
NOP instruction in the routine.