Usart Registers are never written to

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

I am programming an xmega16a4u with a jtagice mkII in Atmel Studio 7.

I am currently trying to get the Usart to work, but the registers are never written to.

My code:

	PORTD.DIR |= (1 << 3);
	PORTD.DIR &= ~(1 << 2);

	USARTD0.BAUDCTRLA |= 0x03;
	USARTD0.BAUDCTRLB |= (0b1001 << 4 | 0x06);
	USARTD0.CTRLA |= USART_RXCINTLVL_LO_gc;
	USARTD0.CTRLB |= USART_TXEN_bm | USART_RXEN_bm;
	USARTD0.CTRLC |= USART_CHSIZE_8BIT_gc;

	while(1)
	{
		while (!( USARTC0.STATUS & USART_DREIF_bm));
		USARTC0.DATA = 0x47;
	}

After executing this code, BAUDCTRLA, for example, still is 0.

 

I am looking forward to your answers.

This topic has a solution.
Last Edited: Sat. Jul 8, 2017 - 06:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that it is not necessarily the case that a hardware register will read-back what you just wrote to it.

 

Are those registers supposed to read-back what you wrote to them?

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

Hmm...  You configure USARTD0, but in the while loop, you are checking the status of USARTC0.  What's up with that?

 

Are you using ASF?

 

Greg Muth

Portland, OR, US

Atmel Studio 7 (Version: 7.0.1652) on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your answer. I simply forgot to reenable the module.