Hallo, ich habe ein Problem mit der "Vordefenition" von
1 | static int8_t uart_getchar(FILE *STREAM) |
2 | {
|
3 | while (!(UCSR0A & (1 << RXC0))); |
4 | return (UDR0); |
5 | } |
So geht es leider nicht.
1 | //Empfaengt 1 Byte vom UART |
2 | static int8_t uart_getchar(FILE); |
Fehlermeldung: Warning 3 'uart_getchar' defined but not used [-Wunused-function] Error 1 conflicting types for 'uart_getchar' Message 2 previous declaration of 'uart_getchar' was here
1 | /* main.c */ |
2 | //#include <string.h> |
3 | //#include <stdlib.h> |
4 | //#include <stdio.h> |
5 | //#include <ctype.h> |
6 | #include <avr/io.h> |
7 | |
8 | //Initialisierung und die Funktionen uart_putchar und art_getchar |
9 | #include "uart.h" |
10 | |
11 | //Eintrag von uart_putchar und uart_getchar als |
12 | //Standard IO |
13 | FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); |
14 | |
15 | int main(void) |
16 | {
|
17 | //Initialisierung (aus serial2.h) aufrufen |
18 | uart_init(F_CPU, BAUD); |
19 | |
20 | //Elementare IO Funktionen als Standard IO eintragen |
21 | stdout = stdin = &mystdout; |
22 | |
23 | printf("\r\nHello World!");
|
24 | while (1) |
25 | {
|
26 | // ... |
27 | } |
28 | } |
1 | /* uart.h */ |
2 | |
3 | #define F_CPU 16000000UL |
4 | #define BAUD 11000 |
5 | |
6 | //#include <string.h> |
7 | //#include <stdlib.h> |
8 | #include <stdio.h> // FILE |
9 | //#include <ctype.h> |
10 | #include <avr/io.h> |
11 | |
12 | //Initialisiert UART gegebener Oszillatorfrequenz und Baudrate |
13 | void uart_init(uint32_t, uint32_t); |
14 | |
15 | //Sendet 1 Byte an UART |
16 | int8_t uart_putchar(char, FILE*); |
17 | |
18 | //Empfaengt 1 Byte vom UART |
19 | static int8_t uart_getchar(FILE); |
1 | /* uart.c */ |
2 | |
3 | #include "uart.h" |
4 | |
5 | void uart_init(uint32_t Oszi, uint32_t Baud) |
6 | {
|
7 | if ((Oszi / 16L / Baud - 1) > 30) |
8 | {
|
9 | UBRR0L = (unsigned char)(Oszi /16L / Baud - 1); |
10 | UBRR0H = (unsigned char)((Oszi / 16L / Baud - 1) >> 8); |
11 | UCSR0A = 0; |
12 | } |
13 | else |
14 | {
|
15 | //Falls Teilerwert zu klein => Rundungsfehler |
16 | //Daher doppelte Rate waehlen |
17 | UBRR0L = (unsigned char)(Oszi / 8L / Baud - 1); |
18 | UBRR0H = (unsigned char)((Oszi / 8L / Baud - 1) >> 8); |
19 | UCSR0A = (1 << U2X0); |
20 | } |
21 | |
22 | UCSR0B = UCSR0B | (1 << TXEN0) | (1 << RXEN0); |
23 | UCSR0C = UCSR0C | (1 << UMSEL01) | (1 << UCSZ01) | |
24 | (1 << UCSZ00); |
25 | } |
26 | |
27 | //Sendet 1 Byte an UART |
28 | int8_t uart_putchar(char data, FILE* stream) |
29 | {
|
30 | while (!(UCSR0A & (1 << UDRE0))); |
31 | UDR0 = (char)data; |
32 | return 0; |
33 | } |
34 | |
35 | //Empfaengt 1 Byte vom UART |
36 | static int8_t uart_getchar(FILE *STREAM) |
37 | {
|
38 | while (!(UCSR0A & (1 << RXC0))); |
39 | return (UDR0); |
40 | } |