Receive data via USART on Atmel SAMD20

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_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?

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

protected by Community♦Feb 19 '18 at 19:50

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?