Atmel SAM D20 USART not working

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

 

I bought an Atmel D20 Xplained Pro board. The BLINK_LED project works fine so I know the board is working.

 

I then then moved to testing the USART in polled mode using the Virtual COM port and I don't receive any characters, even though I'm sending data in a loop. I have tried using Tera Term and PuTTY. I see that the Yellow Status LED lights up when TeraTerm or PuTTY connect. 

 

I commented out the while (1) loop, sent hello world msg just once inside the debugger and I see that usart_write_buffer_wait() returns, implying that the data was sent. But I don't see any data in the terminal.

 

I have pasted my code below. Hope someone can help me figure this out.

 

TIA

Mia Dawson

 

#include <asf.h>

void configure_usart(void);

struct usart_module usart_instance;

void configure_usart(void)
{
	struct usart_config config_usart;

	usart_get_config_defaults(&config_usart);

	config_usart.baudrate    = 9600;
	config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
	config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
	config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
	config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
	config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;

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

	usart_enable(&usart_instance);
}

int main(void)
{
	system_init();

	configure_usart();

	uint8_t string[] = "Hello World!\r\n";
	while (1)
		usart_write_buffer_wait(&usart_instance, string, sizeof(string));

	uint16_t temp;

	while (true) 
	{
		if (usart_read_wait(&usart_instance, &temp) == STATUS_OK) 
		{
			while (usart_write_wait(&usart_instance, temp) != STATUS_OK) 
			{
			}
		}
	}
}

 

Last Edited: Fri. Mar 10, 2017 - 04:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll move this to an ARM forum (you posted in AVR) but before I do I'll just make the point that in AVRs 99.9% of UART problems are because the AVR (and hence UART) are not running at the speed the programmer believes. It might be the case here too. Presumably when you call that usart_init() and pass the 9600 figure it uses it to program a baud rate generator based on some assumption of the CPU speed - perhaps that is wrong?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried the UART sample Project(s) provided by Studio ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

yes, I made the same assumption and tried all the baud rates listed in TeraTerm. None of them worked.

 

thanks

Mia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Have you tried the UART sample Project(s) provided by Studio ?

 

Yes, that is exactly what I did. The code I pasted is from the sample project, minus the comments. I have been testing using the Virtual COM port. One thing I did forget to mention is that I'm running Atmel Studio 7 on a Windows 7 Virtual Machine on a Linux host.

 

thanks

Mia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since I could not make any progress using Virtual COM port, I switched to using an external port. Now I can see on my scope that serial data is being sent out. When I connect a terminal I see that character U is displayed correctly, but others are junk. I have tried using different settings like baud rate, parity, # start/stop bits etc, but no luck.

 

How does one fine tune the baud rate to make this work?

 

gclk_chan_get_hz() returns 8MHz

usart_hw->BAUD.reg = baud;  /* 64277 for 9600 and 65221 for 2400 baud */

 

TIA

Mia

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mia.dawson wrote:

Since I could not make any progress using Virtual COM port, I switched to using an external port. Now I can see on my scope that serial data is being sent out. When I connect a terminal I see that character U is displayed correctly, but others are junk. I have tried using different settings like baud rate, parity, # start/stop bits etc, but no luck.

 

How does one fine tune the baud rate to make this work?

 

gclk_chan_get_hz() returns 8MHz

usart_hw->BAUD.reg = baud;  /* 64277 for 9600 and 65221 for 2400 baud */

 

TIA

Mia

 

 

Hi Mia,

 

Did you have any success in solving your issues?  It would be beneficial to the rest of us who are facing the same issues, if you could post the solution. 

 

Regards,

Jenson

Newbie to the world of Atmel SAM D microcontrollers.

Last Edited: Tue. Dec 5, 2017 - 10:06 AM