简体   繁体   中英

AVR mega2560 uart example errors

when I'm trying to compile the example on the nongnu avr user manual, I get an error:

Here's the example:

#include <stdio.h>
static int uart_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
                                         _FDEV_SETUP_WRITE);
static int
uart_putchar(char c, FILE *stream)
{
  if (c == '\n')
    uart_putchar('\r', stream);
  loop_until_bit_is_set(UCSRA, UDRE);
  UDR = c;
  return 0;
}
int
main(void)
{
  init_uart();
  stdout = &mystdout;
  printf("Hello, world!\n");
  return 0;
}

When I try to compile it, I get errors that UDR, UCSRA, UDRE, and loop_until_bit_is_set are undeclared. Why is this happening?

Thanks!

I solved it by also including <avr/io.h>, adding some of the names, and implementing the init_uart function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM