[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-chat] ATMega UART question
From: |
Preston Wilson |
Subject: |
Re: [avr-chat] ATMega UART question |
Date: |
Sat, 20 Dec 2008 21:35:15 -0500 |
User-agent: |
Microsoft-Entourage/11.4.0.080122 |
First, I have to take back what I said about not seeing a zero byte
transmitted. I simply may not have noticed that behavior. In one project I
have framing around the data I send and receive, and I just ignore data
received outside of a frame. In the another project, the uart is
interacting with a modem, and at startup a zero byte will not cause any
problems. It could be happening, and I just did not notice.
Neither project using these routines is on my bench, or I would check to see
if I get the zero byte on init. If I get time during the holidays, I will
check it out.
> This is the code I have:
> UBRRL = (XTAL / (16L * BAUDRATE)) - 1; //set baud rate;
Does that work? I am not looking at the datasheet, but here is how I setup
the baudrate:
In my case, baudrate is assigned like you have the UBBRL assignment when
U2X0 is not used. Swap out the 16L for an 8L when enabling U2X0.
UART_U2X is #defined to 0x02
flags is of type uint8_t
if (flags & UART_U2X) {
UCSR0A = (1<<U2X0);
}
UBRR0H = (uint8_t)(baudrate >> 8);
UBRR0L = (uint8_t)(baudrate & 0xff);
followed by the code I gave before.
You will have a problem if the upper bits of baudrate are not zero.
> UCSRB = 0x18; // Rx enable Tx Enable
> UCSRC = 0x06; // Asyn,NoParity,1StopBit,8Bit
>
>
> As soon as the RX, Tx enable line executes I see a character sent, the PC
> listening to that UART also receives a byte of zeroes,
-Preston