ATXMEGA128a4u-accesing other USARTs..

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

Hi everyone. 

I have a question regarding using more than 1 USART on the ATXmega128a4u.

I have a board that incorporates an ESP8266 wifi module connected to USARTC0 that is sent through a USB port using CDC.

The board has all pins broken out except for pins PC2 & PC3 which are connected to Tx and Rx of the ESP board.

I would like to know how I would go about accessing another USART to have information passed to it from the ESP8266.

I know the ATXMEGA128a4u has 5 USARTS but am not sure how I would go about setting up another USART. 

Could anyone please help me with this?

The schematic for the board is in the attachment.

Thanks.

STeve.S

Attachment(s): 

This topic has a solution.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The datasheet says the 5 USARTs are identical - so you can just duplicate your USARTx code, replacing all UASRTx references with USARTy

 

It is debatable when it becomes preferable to make a "generic" driver for any USART as opposed to just duplicating the code.

 

But, for generic code, ASF has already done that for you...

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...
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have drivers for each USART, same code as above but changing the USART name ie

xm_usartc0_s.c, xm_usartd0_s.c, xm_usarte0_s.c

 

// USARTE0 driver

#include "xm_usarte0_s.h"

// Make  sure that the TX pin is an output in the init sequence
void USARTE0_init(void)
{
	PORTE_DIR |= (1<<PIN3_bp);		//Set TX pin for output

	USARTE0.BAUDCTRLB = (uint8_t) ((F_CPU / (16UL * baud_USARTE0)) - 1) >>8;	// baud register high
	USARTE0.BAUDCTRLA = (uint8_t) (F_CPU / (16UL * baud_USARTE0)) - 1;			// baud register low	
  	USARTE0.CTRLB = (1<<USART_RXEN_bp | 1<<USART_TXEN_bp ); 					// enable receive and transmit 
}

int USARTE0_putchar(char c, FILE *stream)
{   
	while (!(USARTE0.STATUS & (1 << USART_DREIF_bp)));
	USARTE0.DATA = c;
	return 0;
}

int USARTE0_getchar (FILE *stream)
{
	while(! (USARTE0.STATUS & (1 << USART_RXCIF_bp)));  // wait for data
	return USARTE0.DATA;
}

int	USARTE0_unbuffered_getchar(FILE *stream)
{
	uint8_t c = 0;	//Default return value if no char received

	if (USARTE0.STATUS & (1<<USART_RXCIF_bp))
		{
		c = USARTE0.DATA;
		}
	return c;
}

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sat. Mar 14, 2015 - 09:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And recall that the specific pins used for the USARTS are shown in the Alternate Pin Function of the data sheet.

 

And just a reminder, there are TWO data sheets for each Xmega, one for the family, and one for the specific uC.

 

JC

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

OK all sorted. :) Thanks JS.

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

OHHH WOW one of my replies has been marked as the solution wink need to celebrate.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly