ATMEGA 16 serial communication problem
Parth from India  [1 posts]
15 year
I have to program Atmega16 for serial communication. I have used clock of 16Mhz and CodeVision AVR version 1.24.0 for compiling and programming the AVR.

I am new to AVR programming so decided to use CVAVR

The code that I am using for serial communication of just one character "h" is as follows :

Chip type : ATmega16
Program type : Application
Clock frequency : 16.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256

#include <mega16.h>

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here

void main(void)
// Declare your local variables here

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off

while (1)
// Place your code here


But still i am not recieving 'a' in CVAVR hyperterminal. Please help me.
Anonymous 15 year

Unfortunately we're not familiar with the ATMEGA system and do not have anything to test the above code with. Perhaps others reading this can offer some help. Or alternatively another newsgroup would be a better option.

mehdi from Iran  [32 posts] 15 year
check your AVR clock to be 16MHZ. consider that ATmega16 can not work in 16MHZ with internal clock and to do that,you have to use internal 8MHZ clock or use an external 16MHZ crystal.
check the boudrate in PC and AVR to be same!
and see following code,it may help you!

code vision AVR
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#define xtal 8000000

void main(void)
char tt[10];

UCSRB=0x08; // USART Transmitter: On
UCSRC=0x86; //8 Data, 1 Stop, No Parity
UBRRL=0x33; // USART Baud rate: 2400

Suraj from India  [1 posts] 14 year
thanks a lot dude.....i was using UDR and the scanning while loops and got lost somewhere in there.....scanf and printf were really simple and get the work done.....thanks a ton again
Shashank Kulkarni from India  [1 posts] 13 year
You can refer to the following code for a very simple kind of serial communication using RS232 protocol using ATmega32/16.


This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index