0
\$\begingroup\$

I'm trying to receive some data via USART on Atmel SAMD20. I use usart_read_wait() and usart_read_buffer_wait() but they return with error: the first with STATUS_BUSY and the second with STATUS_ERR_TIMEOUT. Sending works great, I get all the bytes in Putty or minicom. Here is my code:

#include <asf.h>

static struct usart_config usart_conf;
static struct usart_module usart_mod;

int
main (void)
{
  system_init();
  usart_get_config_defaults (&usart_conf);
  usart_conf.pinmux_pad0 = PINMUX_UNUSED;
  usart_conf.pinmux_pad1 = PINMUX_UNUSED;
  usart_conf.pinmux_pad2 = PINMUX_PA20D_SERCOM3_PAD2;
  usart_conf.pinmux_pad3 = PINMUX_PA21D_SERCOM3_PAD3;
  usart_init (&usart_mod, SERCOM3, &usart_conf);
  usart_enable (&usart_mod);
  stdio_serial_init (&usart_mod, SERCOM3, &usart_conf);

  uint8_t buf[8];
  enum status_code st = usart_read_buffer_wait (&usart_mod, buf, sizeof (buf));
  printf ("Code: %d\r\n", st);
}

The uC is connected to the PC via USB-to-TTL serial adapter. I suspect that I did the pinmux configuration the wrong way. I don't really understand what pinmuxes and pads are. So how could I send some data to the uC?

\$\endgroup\$
2
\$\begingroup\$

Did you fix this? It would be great if you could include the complete code you are using. In case you didnt, try putting your usart initialization inside a while cycle.

while (usart_init(&usart_instance,
            EDBG_CDC_MODULE, &config_usart) != STATUS_OK) {
    }

The usart needs some time to complete the initialization process, if you dont use that, it will always fail in the first try. Remember to replace EDBG_CDC_MODULE with the SERCOM you are using in your project

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.