Hallo Zusammen
Ich versuche die Kommunikation zwischen uC Atmega 1284p mit 16MHz und PC
über USART. Dabei benutze ich folgendes Programm, wobei dies
grösstenteils dem Beispiel aus dem Datenblatt entspricht.
Das Problem liegt darin, dass komplett falsche Zeichen ausgegeben
werden. Ich sehe jedoch nicht weiter, wo das Problem liegen könnte.
Im Anhang ist die Ausgabe vom Putty Terminal. Dieses habe ich auf eine
Baudrate von 9600 eingestellt, Parity: none, Flow Control: XON/XOFF, 8
Datenbit, 1 Stopbit
1 | void USART_init( void )
|
2 | {
|
3 | // Initialize the whole USART
|
4 | // Set the baud rate value
|
5 | uint16_t baud = 9600;
|
6 | // Set baud rate
|
7 | UBRR0H = (unsigned char)(baud>>8);
|
8 | UBRR0L = (unsigned char)baud;
|
9 | // Set the XCK0 pin to output
|
10 | DDRB = 0x01;
|
11 | // Enable receiver and transmitter
|
12 | UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
|
13 | // Set frame format: 8data, 1stop bit and synchronous mode
|
14 | UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00) | (1<<UMSEL00);
|
15 | }
|
16 |
|
17 | void USART_transmit( unsigned char data )
|
18 | {
|
19 | // Send the data to the PC
|
20 | // Wait for empty transmit buffer
|
21 | while ( !( UCSR0A & (1<<UDRE0)) )
|
22 | ;
|
23 | // Put data into buffer, sends the data
|
24 | UDR0 = data;
|
25 | }
|
26 |
|
27 | int main(void)
|
28 | {
|
29 | USART_init();
|
30 | while (1)
|
31 | {
|
32 | if(TASTER_EINGANG)
|
33 | USART_transmit('A');
|
34 |
|
35 | }
|
36 | }
|