Ricardo -
Odds are your baud rate is not correct. Either the
processor clock is not what you think it is, or you are
putting an incorrect value into the baud rate generator.
Jim
On Sat, 1 Sep 2007 10:57:25 -0300
"Ricardo Callejo" <surbyte@speedy.com.ar> wrote:
> Hi everyone.
>
> I follow AVRSTUDIO HELP to configure STK500 with
> ATMEGA168.
>
> I flashed some simple programs working with LEDs,
> switches, timers to verify
> the system.
>
> I find troubles when i work with the UART.
>
> I wrote a simple code that works fine with other micros
> like AT90S4433 or
> ATMEGA163, but with ATMEGA168 the program echoes strange
> chars.
>
>
>
> I am using cvavr
>
>
>
> #include <mega168.h>
>
>
>
> // Standard Input/Output functions
>
> #include <stdio.h>
>
>
>
> // Declare your global variables here
>
>
>
> void main(void) {
>
> // Declare your local variables here
>
> char k;
>
>
>
> // The other setting were deleted
>
> /// PORTs, TIMERs, ADC, etc.
>
> /// ....
>
>
>
> // USART initialization
>
> // Communication Parameters: 8 Data, 1 Stop, No Parity
>
> // USART Receiver: On
>
> // USART Transmitter: On
>
> // USART0 Mode: Asynchronous
>
> // USART Baud rate: 19200
>
> UCSR0A=0x00;
>
> UCSR0B=0x18;
>
> UCSR0C=0x06;
>
> UBRR0H=0x00;
>
> UBRR0L=0x0B;
>
>
>
> while (1) {
>
>
>
> /* receive the character */
>
> k = getchar();
>
> /* and echo it back */
>
> putchar(k);
>
> };
>
> }
>
>
>
> What's wrong?
>
>
>
> Ricardo Callejo
>
> SURbyte SRL
>
> San Martin 952
>
> (9000) Comodoro Rivadavia
>
> Chubut - Argentina
>
---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------Message
Re: [AVR-Chat] STK500/Mega168 RS232 problems
2007-09-01 by Jim Wagner
Attachments
- No local attachments were found for this message.