Liebe Kollegen!! Ich schaffe es nicht die UART auf meinem CEREBOT II Board mit einem ATMega64L zum laufen zu bringen. Zur Kontrolle ob Daten gesendet werde bzw. zum empfangen benutze ich Hypertermina. Vielleicht ist jemand so lieb und sieht sich mein Programm an und gibt mir einen Tip bzw. sagt mir wo der Fehler liegt.
1 | #include <avr/io.h> |
2 | #include <avr/interrupt.h> |
3 | //#include <avr/signal.h>
|
4 | #include <inttypes.h> |
5 | #include <avr/delay.h> |
6 | //#include <avr/iom64.h>
|
7 | |
8 | ISR (USART1_RX_vect); |
9 | |
10 | #define F_OSC 8000000 /* oscillator-frequency in Hz */ |
11 | #define UART_BAUD_RATE 9600
|
12 | #define UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) ((F_OSC)/((UART_BAUD_RATE)*16l)-1)
|
13 | |
14 | |
15 | void visableDelay(uint8_t cnt) |
16 | {
|
17 | uint8_t c; |
18 | |
19 | // avr/delay.h _dealy_loop_2() which takes a
|
20 | // uint16_t as its argument
|
21 | // provides a delay determined by the argument,
|
22 | // this delay varies with processor speed
|
23 | // the value is fixed at 0x8000 for an the 8 mhz cerebot
|
24 | for(c = 0; c < cnt; c++) |
25 | {
|
26 | |
27 | _delay_loop_2(0x8000); |
28 | }
|
29 | }
|
30 | |
31 | void usart_putc(unsigned char c) { |
32 | // wait until UDR ready
|
33 | while(!(UCSR1A & (1 << UDRE1))); |
34 | UDR1 = c; // send character |
35 | return; |
36 | }
|
37 | |
38 | |
39 | |
40 | void init(void) { |
41 | // set baud rate
|
42 | |
43 | UBRR1H = (uint8_t)(UART_BAUD_CALC(UART_BAUD_RATE,F_OSC)>>8); |
44 | UBRR1L = (uint8_t)UART_BAUD_CALC(UART_BAUD_RATE,F_OSC); |
45 | UCSR1A = (1 << RXC1); |
46 | // Enable receiver and transmitter; enable RX interrupt
|
47 | UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1); |
48 | |
49 | //asynchronous 8N1
|
50 | UCSR1C = (1 << UCSZ10) | (1 << UCSZ11) | (1 << UMSEL1); //| (1 << UCSZ00) | (1 << UCSZ11); |
51 | return; |
52 | }
|
53 | |
54 | // INTERRUPT can be interrupted
|
55 | // SIGNAL can't be interrupted
|
56 | ISR (USART1_RX_vect) { // USART RX interrupt |
57 | unsigned char c; |
58 | PORTE &= ~(1 << PE6); |
59 | c = UDR1; |
60 | usart_putc(c); |
61 | return; |
62 | }
|
63 | |
64 | int main(void) { |
65 | DDRE = 0xf0; |
66 | //PORTE |= (1 << PE6);
|
67 | init(); // init USART |
68 | //PORTE |= (1 << PE6);
|
69 | sei(); // enable interrupts |
70 | |
71 | // send initial character
|
72 | while(!(UCSR1A & (1 << UDRE1))); |
73 | UDR1 = 0x43; // "C" |
74 | PORTE |= (1 << PE4); |
75 | while(!(UCSR1A & (1 << UDRE1))); |
76 | UDR1 = 0x0d; |
77 | |
78 | // enable PD5 as output
|
79 | |
80 | while (1) { |
81 | // PIN5 PORTD clear -> LED off
|
82 | PORTE &= ~(1 << PE5); |
83 | visableDelay(15); |
84 | // PIN5 PORTD set -> LED on
|
85 | |
86 | PORTE |= (1 << PE5); |
87 | visableDelay(15); |
88 | }
|
89 | return 0; |
90 | }
|
DANKE für Eure Hilfe!!! Freshman