[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] Strange behaivour of UART on mega128
From: |
Jon Sjöstedt |
Subject: |
[avr-libc-dev] Strange behaivour of UART on mega128 |
Date: |
Mon, 30 Oct 2006 10:45:07 +0100 (CET) |
User-agent: |
SquirrelMail/1.4.6-7.el3 |
Hello all!
Having worked for some time with the mega128 i have realized that there is
a problem with the UART. Since i can not tell wether this is a hardware or
a software problem, I start by posting you software guys.
The hardware is Bergmann electronics let-at-work.
I run a very simple program to show the problem. The problem is that the
uart sometimes inserts extra zeros in the datastream. The receiver is a
normal PC running FC3.
The problem only happens if the outputted byte is altered. Also, doing
UDR1 = 1; also affects the output on UART0.
The frequency output of the board is stable at 14.7456MHz. This is
measured using oscilloscope and below program
while(1) { PORTA = ~PINA;}
Any ideas?
#include <avr/io.h>
uint8_t i;
int main()
{
//Configure UART0
UCSR0A =
(1<<U2X0)| // Use double UART speed mode
(0<<MPCM0); // Dont use Multi-procesor communication mode
UCSR0B =
(0<<RXCIE0)| // Dont enable RX complete interrupt
(0<<TXCIE0)| // Dont enable TX complete interrupt
(0<<UDRIE0)| // Dont enable data register empty interrupt
(1<<RXEN0)| // Enable receiver.
(1<<TXEN0)| // Enable transmitter.
(0<<UCSZ02); // Use 8 bit character size
UCSR0C =
(0<<UMSEL0)| // Use asynchronous mode
(0<<UPM01)| // No parity check
(0<<UPM00)| // No parity check
(0<<USBS0)| // Use one stop bit
(1<<UCSZ01)| // Use 8 bit character size
(1<<UCSZ00); // Use 8 bit character size
//115200 @14.7456MHz
UBRR0H = 0; // Use 115200 baud
UBRR0L = 15; // Use 115200 baud
while(1)
{
i = 255;
while(!(UCSR0A & (1<<UDRE0)));
//UDR1 = 1;
UDR0 = 1;
while(!(UCSR0A & (1<<UDRE0)));
i++;
UDR0 = 255;// = i;
i++; if (i > 10) i = 1;
}
return 0;
}
/Jon
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-dev] Strange behaivour of UART on mega128,
Jon Sjöstedt <=