This approach is often called bit banging and can be used to emulate all sorts of communication peripherals. In this case we can implement the communication in Software. Most microcontrollers include a hardware peripheral called UART ( Universal Asynchronous Receiver Transmitter) which handles the serial communication, but some especially small microcontrollers (like the ATtiny24a that I am using) don’t have one. The hardware/software UART works as follows:Īt 9600 baud, with an 8MHz clock, the duration of one bit is 8000000/9600 or 833.3 clock cycles.įirst we disable the USI.The serial port is a very commonly used interface for communicating between a microcontroller and a PC for debugging or sending or receiving some values. If you're prepared to calibrate the internal clock you could dispense with the crystal. The internal clock is only guaranteed to be accurate to within 10% without special calibration, and that isn't really accurate enough for a UART after 5 bits we may be half a bit out. The circuit uses an 8MHz crystal clock for accurate timing. In the ATtiny85 the USI shift register is clocked in on a Timer/Counter0 compare match, so the task is slightly simpler we can set the appropriate count and leave it to receive all 8 bits automatically. The application note is based on the ATtiny26 which has a more primitive timer/counter than the ones in the ATtiny85, and so requires you to reprogram the timer for each of the 8 bits in the byte being received. The ATtiny85 does provide a hardware USI, which can be used to implement two-wire I2C or three-wire SPI, and this can be used to do part of the job in implementing a UART Atmel have written an application note describing how to do this. One way to implement serial communication on the ATtiny85 is using software, but this requires tricky programming to get the timing correct, and ties up the processor making it difficult to synchronise reception of the data with other tasks. Although there are some published routines to do this, they were all a bit complicated, so I set out to write a minimal routine that would do just what I wanted. I wrote this to receive a 9600 baud serial signal from a GPS module using an ATtiny85 processor. This article describes a simple receive-only serial UART for the ATtiny85, using the USI (Universal Serial Interface), the basic serial communication module provided on most ATtiny chips.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |