Hallo,
ich versuche seit gestern RS232 zum laufen zu bringen, aber es klappt irgendwie nicht..
Hier erstmal der Code (fast so wie aus dem AVR Datenblatt):
uart.c
main.cCode:#define BAUD 38400 void usart_init() { /* Calculate baud rate */ uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/(16*BAUD) - 1); /* Set baud rate */ UBRRH = (uint8_t) (ubrr>>8); UBRRL = (uint8_t) ubrr; /* Enable Receiver and Transmitter */ UCSRB = (1<<RXEN) | (1<<TXEN); /* Set frame format: 8data, 2stop bit */ UCSRC = (1<<URSEL) | (1<<USBS) | (1<<UCSZ0); } void usart_transmit(uint8_t data) { /* Wait for empty transmit buffer */ while ( !( UCSRA & (1<<UDRE)) ) ; /* Put data into buffer, sends the data */ UDR = data; } void usart_print(char *s) { do { usart_transmit(*s); } while (*s++); }
Achso, ich benutze einen AVR Mega8Code:#define F_CPU 16000000 #include <avr/io.h> #include <inttypes.h> #include "usart.c" int main(void) { usart_init(); while(1) { usart_print("Test"); } return 0; }
Nur irgendwie empfange ich am Computer gar nix und weiß nicht woran es liegt..
Könnt ihr mir da helfen?
Viele Grüße,
Johannes







Zitieren

Lesezeichen