Enabling AVR UART tx
hi…
this post will cover the topic How to enable and use the inbuilt UART (Universal Asynchronous Receiver Transmitter)??? So lets start with the basic set up we need to do this experiment…
We need…
>>ATmega8 with internal clock source enabled
>>MAX232 it is the rs232->TTL and TTL->rs232 logic level converter.
>>5 Capacitors of value 1uF/63V
>>Serial cable
Now if you have the above hardware stuff with a programmer to program the AVR device; second step is to connect all these stuff to make a set up that can communicate serially with other rs232 compatible devices, once programmed. For that here is the connection scheme…
Why we need a logic converter (TTL <–> RS232)???
As our AVR microcontroller deals only with TTL signal level for communicating with external world but RS232 standard has logic level voltages somewhat different. For RS232 Logic 0 = -25V while Logic 1= +25V.
Here is the code that continously sends a string to the PC asynchronously.
/************************************************************/
#include<avr/io.h>
void UART_transmit(unsigned char data);
int main(void)
{
unsigned char i,message[]="devesh samaiya\r\n";
DDRD=0x00;
PORTD=0xFF;
UCSRA=0;
UCSRB=1<<TXEN; // transmitter enable
UCSRC=1<<URSEL | 1<<UCSZ1 | 1<<UCSZ0; // 8 data bit, a stop, none parity
UBRRH=0;
UBRRL=5; // for 9600 baud at 1MHz
while(1)
{
for(i=0;message[i];i++)
{
UART_transmit(message[i]);
}
}
}
void UART_transmit(unsigned char data)
{
while(!(UCSRA & (1<<UDRE)));
UDR=data;
}
/*****************************************************************/





