Again an usart problem... [solved/RTFM]

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

USART again!!
I come here only after a long moment trying.

My atmega8 with 8mhz crystal communicate via usart with my pc.

I configure every one to 9600 bauds.

I can only use UART with 300 bauds!!!!

I note that 9600/300=32.

Configuration :

#define BAUDRATE     9600//9600            // desired baud rate
#define BAUD_PRESCALE (((F_CPU / (BAUDRATE * 16UL))) - 1)
...
...

void InitUART (unsigned char baudrate) {
  UBRRL = baudrate;
  UCSRB = (1<< RXEN) | (1<<TXEN); 
  UCSRC = (1<<UCSZ1)|(1<<UCSZ0);
}
...
...

InitUART(BAUD_PRESCALE);

If somebody got an idea, thanks...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

Last Edited: Sat. Dec 5, 2009 - 05:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PS
All the stuff is ok with a attiny2313...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-- What F_CPU are you building with? How have you verified it?
-- What BAUD_PRESCALE is being calculated? How have you verified it?
-- What speed is your AVR really running at? How have you verified it?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

UCSRC = (1<<UCSZ1)|(1<<UCSZ0);

Is that the correct way to write to UCSRC on that AVR model?

Hint: "See the “Accessing UBRRH/UCSRC Registers” on page 148 section which describes how to access this register."

Another hint: Many/most times the default value for UBRRC is used anyway.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks
I'm looking for 8Mhz
I verified my formula for prediviser of the baud rate.
delay_ms(1000); give one sedcond delay...

On my datasheet (atmega8) it's on page 152.

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
On my datasheet (atmega8) it's on page 152.

But have you read that section and corrected your code to match?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it's ok with :

 UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);

:)
in datasheet i see :

The URSEL must be one when writing the UCSRC

But i don'y understand what is the use of URSEL...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

UCSRC and UBRRH share the same I/O address. That bit tells the AVR which register you really want to write to. Without that bit being set, the code:

UCSRC = (1<<UCSZ1)|(1<<UCSZ0); 

sets UBRRH to 0x06, which means that you end up setting UBRR to 1587. As a result you end up running at ~314 baud instead of 9600 baud.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zettaman wrote:
But i don'y understand what is the use of URSEL...
Simply read the chapter
USART - Accessing UBRRH/UCSRC Registers

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everybody
I will read datasheet slower...

I think that's they call this in US the "RTFM" syndrom.

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1