avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Problem with USART on AVR


From: jack
Subject: Re: [avr-chat] Problem with USART on AVR
Date: Tue, 06 Mar 2007 22:36:44 +0530
User-agent: Thunderbird 1.5.0.9 (Windows/20061207)

copy-paste error in main

int
main(char **argv, char argc) {
  usart_init();
  while(1) {
      usart_trx_flash("Hello, World!!\n");
  }
}

Thankx,
Jack

jack wrote:
Thankx for the reply Hugo.

The issue is resolved for now. I was using USB to serial cable on my laptop and that was causing the issue (not sure how). I tried connecting directly to the serial port on my PC and everything works fine.

I have also pasted my USART code below:


#define    F_OSC      ((unsigned long) (12*1000000))
#define    BAUD_RATE  ((unsigned long) (19200))
#define MYUBRR ((unsigned long)(F_OSC/(unsigned long)(16*BAUD_RATE) - 1))

void
usart_init(void) {
   UBRRL = (unsigned char) (MYUBRR);
   UBRRH = (unsigned char) (MYUBRR >> 8);
   UCSRA &= !(1<<U2X);                  // Set U2X = 0
   UCSRB = (1<<RXEN) | (1<<TXEN);       // polling mode.
UCSRC = (1<<USBS) | (3<<UCSZ0); // No parity, 8 Databit, 1 stop bit.
}

void
usart_trx(char c) {
   while (!(UCSRA & (1<<UDRE)));
   UDR = c;
}

char
usart_rcx(void) {
   while (!(UCSRA & (1<<UDRE)));
   return UDR;
}

void
usart_trx_flash(const prog_char* str) {
   const prog_char *p=str;
   while (*p) {
       usart_trx(*p);
       p++;
   }
}

int
main(char **argv, char argc) {
   while(1) {
       usart_trx_flash("Hello, World!!\n");
   }
}

Thankx,
Jack

Hugo González Monteverde wrote:
What baudrate are you using? What is the code you use for initializing UBRRH and UBRRL?

Looks like maybe you are using a high error baudrate with your clock....

Hugo

jack wrote:
Hi All,

I am trying to run USART on ATTiny2313 at 12MHz but am seeing junk values in between at random. Sometimes some chars in the buffer are also skipped. It's seen more often when i am transmitting anything from SRAM rather than FLASH.


_______________________________________________
AVR-chat mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-chat








reply via email to

[Prev in Thread] Current Thread [Next in Thread]