0

hope you are having a great time getting to the point these past days I have been working with a MicroChip Curiosity Nano (ATmega4809) trying to enable a communication by UART ports on Microchip Studio, when the only way I could establish this is when I use al the default configuration (8 bits frame,none parity,1 stop bit) but when try to configure to a 9 bit frame I started to recieve some weird characters.

I have done several changes on this configuration according to datasheet based on registers managment but always the same results.

void USART0_init(void)
{
    USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);
    USART0.CTRLB |=  USART_RXEN_bm | USART_TXEN_bm;
    
    //Tries I have done
    //#define USART_CHSIZE_gm 0x07
    //USART0.CTRLC |= USART_CHSIZE_gm;
    //USART0.CTRLC |= (7<<USART_CHSIZE_gm);
    //USART0.CTRLC |= (1<<USART_CHSIZE2_bm) | (1<<USART_CHSIZE1_bm) | (1<<USART_CHSIZE0_bm);    
    
    PORTA.DIR |= PIN0_bm;
    PORTA.DIR &= ~PIN1_bm;
    
}

This code is the UART port's inizialization, and the lines I have commented are about the configuration I need to get 9 bits frame communication, also I mentioned before when I commented this part it works correctly to 8 bits frame communication.

Thanks for taking the time and have a nice day.

  • 9 bits per character -- weird. Please share with us the sent and received damaged data. For debugging I would go into two directions: 1. Configure the sender to 8E1 and the receiver to 9N1. The sent parity bit should arrive as 9th data bit. 2. try to set the three lower bits in CTRLC to six. – user5329483 Apr 12 '22 at 20:12
  • As @user5329483 asked, describe the other end of the serial link. See https://stackoverflow.com/questions/57193363/stty-serial-port-settings-for-parity-not-persistent/57318783#57318783 for remarks on using serial ports for 8-bits with parity and 9N1 (i.e. 11-bit frames). Maybe you need to use an oscilloscope to verify what's on the wire. – sawdust Apr 22 '22 at 07:58

0 Answers0