WinAvr USART problem

Gast #1309165
Lesenswert?

Hallo,

was ist dem an dem Code Falsch?
Als Compiler verwnde ich WinAvr
1
#include <avr/io.h>
2

3
#define USART_BAUDRATE 9600
4
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
5

6
int main (void)
7
{
8
   char ReceivedByte;
9

10
   UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
11
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
12

13
   UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
14
   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
15

16
   for (;;) // Loop forever
17
   {
18
      while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been recieved and is ready to be read from UDR
19
      ReceivedByte = UDR; // Fetch the recieved byte value into the variable "ByteReceived"
20

21
      while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
22
      UDR = ReceivedByte; // Echo back the received byte back to the computer
23
   }   
24
}

Als Fehlermeldung erhalte ich:

main.c:10: error: 'UCSRB' undeclared (first use in this function)
main.c:10: error: (Each undeclared identifier is reported only once
main.c:10: error: for each function it appears in.)
main.c:11: error: 'UCSRC' undeclared (first use in this function)
main.c:11: error: 'URSEL' undeclared (first use in this function)
main.c:13: error: 'UBRRL' undeclared (first use in this function)
main.c:14: error: 'UBRRH' undeclared (first use in this function)
main.c:18: error: 'UCSRA' undeclared (first use in this function)
main.c:19: error: 'UDR' undeclared (first use in this function)

Und zwar immer wenn ich den USART beutzen möcht auch bei anderen Codes.

mfg alex
Persönliche Seite #1309195
Lesenswert?

> UCSRB anstatt UCSRA nützt auch nichts.

Das kann auch logisch nichts bringen. Das würde eine ganz andere 
Funktionsweise im Programm auslösen.

Es liegt ein heftigeres Problem vor. Es kann sein, dass nicht das 
erwartete Makefile benutzt wird oder die MCU betreffende Zeile im 
Compileraufruf falsch ist. Hänge mal das Makefile an. Rufe mal make mit 
der -d Option auf.
#1309219
Lesenswert?

Wieso hat dein Makefile die Endung .lib?

Ein Makefile hat keine Endung (oder eine leere Endung, je nachdem wie 
man das sehen will). Kann es sein, dass du eine andere Datei 'Makefile' 
auf deinem Verzeichnis hast? (Das würde dann von make benutzt werden und 
dein Makefile.lib ist zwar nett aber nutzlos)

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren