Hi all,

I am trying to implement a USART receiver, for which I need to select the baud rate. This is my first time doing bare metal on a SAM MCU, and I jut wanted understand how to calculate the baud rate. I found the following microchip article detailing how to calculate the baud rate: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42539-SAMD-SERCOM-USART-Configuration_ApplicationNote_AT11626.pdf

In the doc, the following function (long_division) is used as part of the calculation of the baud rate (the full calculation is detailed in page 16 of the document. Here is a snippet of the baud rate calculation function:

static uint64_t long_division(uint64_t n, uint64_t d) { int32_t i; uint64_t q = 0, r = 0, bit_shift; for (i = 63; i >= 0; i--) { bit_shift = (uint64_t)1 << i; r = r << 1; if (n & bit_shift) { r |= 0x01; } AT11626: SAM D SERCOM USART Configuration [APPLICATION NOTE] Atmel-42539A-SAMD-SERCOM-USART-Configuration_ApplicationNote_AT11626_092015 1 6 16 if (r >= d) { r = r - d; q |= bit_shift; } } return q; }

I just wanted to understand, is this the way the baud rate should be calculated? I had originally done it the following way:

uint64_t br = (uint64_t)65536 * (F_CPU - 16 * baud) / F_CPU; // Variable for baud rate

I used the calculation based on what was detailed on the MCU's datasheet.I just want to make sure that I am using the expected baud rate (9600) as I am not sure I am received the right data.