cpu/sam0_common: uart: fix baud rate calculation

In fractional mode, 3 bits are used to store the fractional part.
Therefore we must multiply / divide by 8 instead of 10 in order to
get the correct values.
This commit is contained in:
Benjamin Valentin 2019-09-26 12:28:22 +02:00
parent 736e5e5a35
commit 7e5aa7e775

View File

@ -89,9 +89,9 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
} }
/* calculate and set baudrate */ /* calculate and set baudrate */
uint32_t baud = ((((uint32_t)CLOCK_CORECLOCK * 10) / baudrate) / 16); uint32_t baud = ((((uint32_t)CLOCK_CORECLOCK * 8) / baudrate) / 16);
dev(uart)->BAUD.FRAC.FP = (baud % 10); dev(uart)->BAUD.FRAC.FP = (baud % 8);
dev(uart)->BAUD.FRAC.BAUD = (baud / 10); dev(uart)->BAUD.FRAC.BAUD = (baud / 8);
/* enable transmitter, and configure 8N1 mode */ /* enable transmitter, and configure 8N1 mode */
dev(uart)->CTRLB.reg = SERCOM_USART_CTRLB_TXEN; dev(uart)->CTRLB.reg = SERCOM_USART_CTRLB_TXEN;