Hallo, mein Atmega8 sendet nur nullen, wenn ich per USART_transmit etwas senden möchte. Mein Terminalprogramm ist auf 9600 baud, 2 stoppbits eingestellt. Loopback auf TTL-Seite des MAX232 funktioniert problemlos. Hat vielleicht jemand eine Idee, woran es liegen könnte? Danke :) (Es folgt der relevante Codeausschnitt)
1 | #ifndef F_CPU
|
2 | #define F_CPU 4000000
|
3 | #endif
|
4 | |
5 | #include <avr/io.h> |
6 | #include <inttypes.h> |
7 | #include <util/delay.h> |
8 | #include <stdlib.h> |
9 | #include <avr/interrupt.h> |
10 | |
11 | #define uchar unsigned char
|
12 | #define uint unsigned int
|
13 | |
14 | #define FOSC 4000000 // Clock Speed
|
15 | #define BAUD 9600
|
16 | #define MYUBRR FOSC/16/BAUD-1
|
17 | |
18 | // procedures
|
19 | |
20 | void USART_Init(unsigned int ubrr); |
21 | void USART_Transmit(unsigned char data); |
22 | |
23 | int main(void) |
24 | {
|
25 | USART_Init(MYUBRR); // initialize USART |
26 | |
27 | for(;;) { |
28 | USART_Transmit(65); |
29 | }
|
30 | }
|
31 | |
32 | void USART_Init(unsigned int ubrr) |
33 | {
|
34 | /* Set baud rate */
|
35 | UBRRH = (unsigned char)(ubrr>>8); |
36 | UBRRL = (unsigned char)ubrr; |
37 | /* Enable receiver and transmitter */
|
38 | UCSRB = (1<<RXEN)|(1<<TXEN); |
39 | /* Set frame format: 8data, 2stop bit */
|
40 | UCSRC = (1<<USBS)|(3<<UCSZ0); |
41 | }
|
42 | |
43 | void USART_Transmit( unsigned char data ) |
44 | {
|
45 | /* Wait for empty transmit buffer */
|
46 | while ( !( UCSRA & (1<<UDRE)) ) |
47 | ;
|
48 | /* Put data into buffer, sends the data */
|
49 | UDR = data; |
50 | }
|