ismbn
Full Member level 3
- Joined
- Feb 11, 2012
- Messages
- 160
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 1,308
- Location
- Mumbai. india
- Activity points
- 2,444
Hello...
I am using the AT MEGA 32 and AVR studio 4.
In that i have given the F_CPU = 16000000 i.e 16MHz.
The Problem is I giving the UBRR = 51 (or any other value given in the data sheet) as given in the data sheet to set the Baud rate 19200.
But in the Hardware as well as in Simulation it is not working on 19200. but it is working on Baud Rate 2400(and if i am giving 103 for 9600 it is working on 1200). What can be the problem please guide me.
I am using Crystal of 16MHz, Is using the crystal of 16MHz is right or i have to use low value of crystal ?
here is the code:
Ismail
I am using the AT MEGA 32 and AVR studio 4.
In that i have given the F_CPU = 16000000 i.e 16MHz.
The Problem is I giving the UBRR = 51 (or any other value given in the data sheet) as given in the data sheet to set the Baud rate 19200.
But in the Hardware as well as in Simulation it is not working on 19200. but it is working on Baud Rate 2400(and if i am giving 103 for 9600 it is working on 1200). What can be the problem please guide me.
I am using Crystal of 16MHz, Is using the crystal of 16MHz is right or i have to use low value of crystal ?
here is the code:
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
int i=0,j=0;
int main (void)
{
int a;
DDRA=0xFF;
DDRB=0xFF;
a=51; // to set the boud rate 19200
UBRRL = a;
a=a>>8;
UBRRH = a;
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1<<U2X)| (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
// UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
// BAUD_PRESCALE=(BAUD_PRESCALE>>8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
// UBRRH = (BAUD_PRESCALE>>8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UCSRB |= (1 << RXCIE);// Enable the USART Recieve Complete interrupt (USART_RXC)
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed
for (;;) // Loop forever
{
PORTA=j; // Do nothing - echoing is handled by the ISR instead of in the main loop
_delay_ms(10);
j++;
}
}
ISR(USART_RXC_vect)
{
char ReceivedByte;
ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived"
UDR= ReceivedByte ; // Echo back the received byte back to the computer
PORTB=i++;
}
Ismail