Das Programm soll das Empfangene Byte immer wieder wiederholen. Jedoch Empfange ich nach dem ich ein Byte zum µC geschickt habe, nichts mehr. Wo liegt mein Fehler?
1 | #define F_CPU 16000000
|
2 | |
3 | #define baud_value 103 //baudrate = 9600
|
4 | |
5 | #define Zeilenumbruch "\r\n"
|
6 | |
7 | #include <avr/io.h> |
8 | #include <math.h> |
9 | #include <util/delay.h> |
10 | #include <avr/interrupt.h> |
11 | |
12 | uint8_t UARTReceivedByte; |
13 | |
14 | void uartInit(void){ |
15 | UCSR0C |= (1<<UPM01); //Even Parity |
16 | UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00); // 8 Bit, 1 Stopbit, Asynchronos |
17 | UBRR0H = (unsigned char) (103 >> 8); //baudrate = 9600 |
18 | UBRR0L = (unsigned char) 103; |
19 | UCSR0B |= (1<<RXCIE0); //Receive Interrupt |
20 | UCSR0B |= (1<<RXEN0) | (1<<TXEN0); //TX und RX aktiviert |
21 | sei(); |
22 | }
|
23 | |
24 | void uartTransmitByte (uint8_t data) |
25 | {
|
26 | while (! (UCSR0A & (1 << UDRE0)) ) |
27 | {
|
28 | |
29 | }
|
30 | UDR0 = data; |
31 | }
|
32 | |
33 | void uartTransmitString (char *s) |
34 | {
|
35 | while (*s){ /* so lange *s != '\0' also ungleich dem "String-Endezeichen(Terminator)" */ |
36 | uartTransmitByte(*s); |
37 | s++; |
38 | }
|
39 | }
|
40 | void adcInit(void){ |
41 | ADMUX |= (1<<REFS0); //sets Reference to AVCC |
42 | ADMUX |= (1<<ADLAR); //sets ADC Result to ADCH |
43 | ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //Prescaler = 128 -> ADC Clock = 125 kHz |
44 | ADCSRA |= (1<<ADEN); |
45 | ADCSRA |= (1<<ADSC); //stabilise |
46 | }
|
47 | |
48 | uint8_t adcRead(void){ |
49 | int ADCResult; |
50 | ADCSRA |= (1<<ADSC); //start Conversion |
51 | while (ADCSRA & (1<<ADSC)) //wait until conversion has ended |
52 | {
|
53 | ;
|
54 | }
|
55 | ADCResult = ADCH; //ADC Result |
56 | return ADCResult; |
57 | }
|
58 | |
59 | ISR(USART_RX_vect){ |
60 | UARTReceivedByte = UDR0; |
61 | }
|
62 | |
63 | int main(void) |
64 | {
|
65 | uartInit(); |
66 | |
67 | while(1) |
68 | {
|
69 | uartTransmitByte(UARTReceivedByte); |
70 | _delay_ms(1000); |
71 | }
|
72 | }
|
mfg