USART3 is the only working in ATmega4809

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

Hi all.

I am new to AVR and now I'm studying ATmega4809 Curiosity Nano board. I would like to explore the USART pins of the board. In the data sheet, if I'm not mistaken, there are 3 pairs of TX and RX (PA0,PA1, PB0,PB1, PC0,PC1).
In my code, I used USART3 and PORTB (PB0 and PB1) pins, and it's working, there's no problem with it.

 

However, I am just wondering why can't I use the pins PA0,PA1 and PC0,PC1? 
I've tried replacing the USART3 to USART0, USART1, USART2 while using PORTA or PORTC pins but it's really not working.

 

My question is, are there any relation between USARTn and PORTn to be used?

 

Here is the code for your reference:

#include <avr/io.h>
#include <avr/delay.h>

#define F_CPU 3333333ul																
#define BAUD_RATE3 9600ul																
#define USART0_BAUD_RATE (F_CPU * 4 / BAUD_RATE3)			
#define MAX_COMMAND_LEN 8

char String[] = "hello world";

void usart_init()
{
  PORTA.DIRSET = PIN0_bm;												
  PORTA.DIRCLR = PIN1_bm;													
  USART0.BAUD = USART0_BAUD_RATE;
  USART0.CTRLA |= USART_TXEN_bm | USART_RXEN_bm;
}
  
void usart_putchar(char *StringPut)
{
  while(*StringPut != 0x00)										
  {
    while((USART0.STATUS & USART_DREIF_bm) == 0); 
    {																							
      USART0.TXDATAL = *StringPut;
    }
    StringPut++;
  }
}

int main(void)
{	
  usart_init();
  while (1)
  {
    usart_putchar(String);
    _delay_ms(1000);
  }
}

 

This topic has a solution.

I'm new.

Last Edited: Fri. Jan 3, 2020 - 03:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To use the other port options, you need to control the PORTMUX. You need to review the Port Multiplexer section of the "megaAVR 0-Series manual" (Chapter 14) and section 4.1 of the "ATmega3209/4809 - 48 pin Data Sheet". I don't see any access to PORTMUX in your code, above.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Dec 27, 2019 - 05:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim!

I am very sorry for replying so late. Thanks for the reply! I just noticed the USARTn (like 0,TxD or 3,TxD) in the ATmega3209/4809 - 48 pin Data Sheet, so it really is a big help. 

 

So far, I now know that USART of pins in:

PORTA = USART0

PORTB = USART3

PORTC = USART1

PORTF = USART2

 

Now, I really think I need a bit of help in understanding this:

To my understanding, "PORTMUX.USARTROUTEA = 1" commands the USART to use the alternative pins (like PB0&PB1 to PB4&PB5).

But I really do not get how to use the PORTMUX in using the other USART(0,1,2).

I'm new.

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

Upon more reading, I've learned that Pins PB0 and PB1 are ATmega4809's CDC RX and TX.

Does this mean that only USART of PB0 and PB1 can be viewed in a terminal (like Data Visualizer or PuTTY)?

 

I appreciate any insight on this.

I'm new.

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

PB0/PB1 connect to the debug chip CDC port

If you want to see the other UART ports work, you have to connect those pins to some sort of UART device, like a USB/Serial converter board, external to the curiosity board itself.

I have working boards with 4809 chips using B4 and A4 as the UARTTX pins, and an Xplained Pro that uses C0/C1, so I'm pretty sure that other UARTS work...

 

are there any relation between USARTn and PORTn to be used?

Yes.

You have a total of 4 UARTs (on ports A, B, C, and F), each of which can appear on two different sets of pins.  You shouldn't need to play with PORTMUX if you stay on the default pins for each UART.

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

westfw wrote:

PB0/PB1 connect to the debug chip CDC port

If you want to see the other UART ports work, you have to connect those pins to some sort of UART device, like a USB/Serial converter board, external to the curiosity board itself.

 

Oh, so an external board is required to use the other UART ports. That's the answer I'm looking for! Haha thank you very much!

I'm new.

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


It's always worth a look at the board schematic - this should have been immediately obvious from the schematic.

 

The text in the User Guide does seem unnecessarily vague - just talking about "a UART" - without telling you which one!

 

frown

 

But it is clear that it's just one.

 

The details are in Fig 4-1 on page 14, and Table 4-4 on page 16:

 

 

 

http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega4809-Curiosity-Nano-HW-UG-DS50002804A.pdf

 

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: 1

 

 

francoder wrote:
an external board is required to use the other UART ports

Not necessarily a board - you just need to make the connections.

 

You can get USB-to-UART cables which connect directly to logic-level UART pins - just be sure to get one which supports the correct voltage levels (5V / 3V / 1.8V / whatever).

 

eg,

 

   

 

https://www.ftdichip.com/Products/Cables/USBTTLSerial.htm

 

 

EDIT

 

The Curiosity Board manual also shows you how to break the default connection - having done that, you could then wire an alternate connection on the board to use the built-in VCP ...

 

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...
Last Edited: Fri. Jan 3, 2020 - 10:31 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

francoder wrote:

while((USART0.STATUS & USART_DREIF_bm) == 0); 
    {																							
      USART0.TXDATAL = *StringPut;
    }

wow that's misleading! I had to look at that twice to see that the semicolon separates the conditional and the statement block. What on earth are the braces and indentation doing here?