6967 views|3 replies

31

Posts

0

Resources
The OP

Atmega16 serial port baud rate setting problem [Copy link]

I just learned AVR. According to the tutorial, I set the serial port baud rate to 9600. However, when debugging with the serial port, the baud rate must be 600 to output normally. Why is it not 9600? The code is as follows: #include
#include
#include

#define F_CPU 16000000 #define BAUD 9600 int main(void) { unsigned char temp = 0x55; DDRB = 0xff; PORTB = 0xaa; UBRRH = ( F_CPU/BAUD/16 - 1 ) / 256; /*Set baud rate*/ UBRRL = ( F_CPU/BAUD/16 - 1 ) % 256; UCSRB |= ( 1 << RXEN ) | ( 1 << TXEN ) | ( 1 << RXCIE ); /*Receive enable, transmit enable, receive end interrupt enable*/ sei(); /*Enable global interrupt*/ while(1) { while( !( UCSRA & ( 1 << UDRE ) ) ); temp = ~temp; UDR = temp; PORTB = ~PORTB; _delay_ms( 1000 ); } return 0; } Please give me some advice, thank you
This post is from Microchip MCU

Latest reply

I think the problem is in your fuse position. The baud rate you use is 9600, but it is actually 600. 9600/600=16. The difference is 16 times. The crystal oscillator you use is 16M, and the internal RC oscillator is 1M, which is exactly 16 times different. This should not be a coincidence, right? Think about it? ::loveliness:  Details Published on 2014-4-20 23:56

502

Posts

1

Resources
2
Is it about the crystal? At the beginning of AVR, it seems that the internal 1M RC oscillator is usually selected. If the crystal oscillator is selected externally, the fuse position is adjusted.
This post is from Microchip MCU

1291

Posts

0

Resources
3
Modify the fuse position, select the external crystal oscillator, and see if the voltage supports 16M. If not, change to an 8M external crystal oscillator. At the same time, the software should also be modified to match the crystal oscillator frequency.
This post is from Microchip MCU

20

Posts

0

Resources
4
I think the problem is in your fuse position. The baud rate you use is 9600, but it is actually 600. 9600/600=16. The difference is 16 times. The crystal oscillator you use is 16M, and the internal RC oscillator is 1M, which is exactly 16 times different. This should not be a coincidence, right? Think about it? ::loveliness:
This post is from Microchip MCU

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list