With serial communication you can exchange data with the AVR-microcontroller and your PC. Allmost all AVR-microcontroller have a UART (Universal Asynchronous Reciever/Transmitter) on board of the chip (accept for some ATTiny microcontrollers).
The data transmission between the PC and the microcontroller is serial and asynchronous, serial means that the bits are send one after the other and asynchronous means that there is no clock signal to clock in the data that is send or recieved. One byte is transmitted in 10 bits, 1 start bit, 8 data bits and one stop bit, as you can see in the figure below.
The serial data transmission has a standard that is called RS232. According to this standard a logical "0" has a voltage level between -15V and -5V and a logical "1" has a level between +5V and +15V. The AVR-microcontrolers use 5V (TTL-level) to transmit signals. So the signals needs to be converted, this can be done with the MAX232 IC, that only needs a 5V power supply to convert the signal from TTL-level to RS232 level and reverse.
Transmission between two RS232 devices can take place with a maximum distance of 15 meters.
Below you can see the schematic of how the RS232 convertor is connected to the ATTiny2313 microcontroller. The ATTiny2313 board is equiped with the hardware for serial communication with your PC. You can buy the ATTiny2313 board at www.bizztronix.eu.
The software is written on C The program sends a text string to the microcontroller and echos it back to the terminal.
First step of the program is the initialization of the UART, that is setting the baud rate, enable the transmitter and receiver and setting the frame rate.
To test the program you can use the BR@y terminal emulator.The settings for the COM port are: COM1,9600,N,8,1.
// program name: UART send/receive text
#define FOSC 16000000 // set clock speed
void usart_init(unsigned int ubrr)
void usart_transmit(unsigned char data)
void transmit_text(char text)
unsigned char usart_receive(void)
void receive_text (char text)