Hi zusammen,
so richtig will's immernoch nicht klappen...
Das Schreiben scheint zu klappen, aber ich hab echt das Gefühl, dass der µC nicht mit dem Lesen klar kommt.
Folgender Code:
Folgende Ausgabe auf dem Terminal:Code:#include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> #define Pin1 0 #define Pin2 1 #define Pin3 2 #define Pin4 3 #define Pin5 4 #define Pin6 5 #define Pin7 6 #define Pin8 7 #define READ 1 #define WRITE 2 #define F_CPU 8000000 #define USART_BAUD_RATE 9600 #define USART_BAUD_SELECT (F_CPU/(USART_BAUD_RATE*16l)-1) volatile unsigned char data; void usart_init(int Enable, int Interupts) { if (Enable == READ) UCSRB = (1<<RXEN); if (Enable == WRITE) UCSRB = (1<<TXEN); if (Enable == READ + WRITE) UCSRB = ( (1<<RXEN) | (1<<TXEN) ); if (Interupts == READ) UCSRB |= (1<<RXCIE); if (Interupts == WRITE) UCSRB |= (1<<TXCIE); if (Interupts == READ + WRITE) UCSRB |= ( (1<<RXCIE) | (1<<TXCIE) ); UBRRL = (unsigned char) USART_BAUD_SELECT; } void usart_writeChar(unsigned char c) { while (!(UCSRA & (1<<UDRE))) {} UDR = c; } unsigned char usart_readChar(void) { while(!(UCSRA & (1<<RXC))) {} return UDR; } void usart_writeString(unsigned char *string) { while (!(UCSRA & (1<<UDRE))) {} while ( *string) usart_writeChar(*string++); } SIGNAL (SIG_UART_RECV) { data = UDR; } int main (void) { usart_init(READ + WRITE, READ); DDRD = 0xFF; PORTD = 0x00; usart_writeString("Hello World"); sei(); while (1) { if (data == 'l') { PORTD = (1 << Pin6); usart_writeString("[Motor left]"); } else if (data == 'r') { PORTD = (1 << Pin7); usart_writeString("[Motor right]"); } else if (data == 's') { PORTD = 0x00; usart_writeString("[Motor stop]"); } else usart_writeChar(data); } }
Das seltsame ist, dass ich über das Terminal gar nichts schicke, was das USART empfangen könnte.Hello World[Motor right]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]ht]
...
Trotzdem wird die IF Schleife (data == 'r') ausgelöst, dabei kann data gar nicht 'r' sein![]()







Zitieren

Lesezeichen