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); } }