Hello
I'm finally finding some time to play with my AVRDA's (always used mega's before) and I'm puzzled with some USART output
About half of the time the sent byte has a bit that is far too short, never the same bit, never the same actual/expected time ratio
Here is a code reproducing the problem, inspired by the Microchip example at Github (https://github.com/MicrochipTech/avr128da48-usart-example)
I attached the measured output too
#include <avr/io.h> #include <util/delay.h> #define USART_BAUD_RATE(BAUD_RATE) ((float)(64 * F_CPU / (16 * (float)BAUD_RATE)) + 0.5) void USART_sendChar(char c){ while(!(USART0.STATUS & USART_DREIF_bm)){} USART0.TXDATAL = c; } void main(){ PORTA.DIRSET = PIN0_bm; _PROTECTED_WRITE(CLKCTRL.OSCHFCTRLA, CLKCTRL_FREQSEL_8M_gc); _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, 0); USART0.BAUD = (uint16_t)(USART_BAUD_RATE(115200)); USART0.CTRLC = USART_SBMODE_bm | USART_CHSIZE0_bm | USART_CHSIZE1_bm; PORTA.DIRSET = PIN0_bm; USART0.CTRLB |= USART_TXEN_bm; while(1){ _delay_us(150); USART_sendChar(0x55); } }
I tried with FREQSEL from 2 to 24MHz but nothing helped
I guess it's my fault but I can't see what I'm missing here