Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,21 @@ void SERCOM::initUART(SercomUartMode mode, SercomUartSampleRate sampleRate, uint

if ( mode == UART_INT_CLOCK )
{
uint16_t sampleRateValue ;
uint16_t sampleRateValue;

if ( sampleRate == SAMPLE_RATE_x16 )
{
sampleRateValue = 16 ;
}
else
{
if ( sampleRate == SAMPLE_RATE_x8 )
{
sampleRateValue = 8 ;
}
else
{
sampleRateValue = 3 ;
}
if (sampleRate == SAMPLE_RATE_x16) {
sampleRateValue = 16;
} else {
sampleRateValue = 8;
}

// Asynchronous arithmetic mode
// 65535 * ( 1 - sampleRateValue * baudrate / SystemCoreClock);
// 65535 - 65535 * (sampleRateValue * baudrate / SystemCoreClock));
sercom->USART.BAUD.reg = 65535.0f * ( 1.0f - (float)(sampleRateValue) * (float)(baudrate) / (float)(SystemCoreClock));
// Asynchronous fractional mode (Table 24-2 in datasheet)
// BAUD = fref / (sampleRateValue * fbaud)
// (multiply by 8, to calculate fractional piece)
uint32_t baudTimes8 = (SystemCoreClock * 8) / (sampleRateValue * baudrate);

sercom->USART.BAUD.FRAC.FP = (baudTimes8 % 8);
sercom->USART.BAUD.FRAC.BAUD = (baudTimes8 / 8);
}
}
void SERCOM::initFrame(SercomUartCharSize charSize, SercomDataOrder dataOrder, SercomParityMode parityMode, SercomNumberStopBit nbStopBits)
Expand Down
5 changes: 2 additions & 3 deletions cores/arduino/SERCOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ typedef enum

typedef enum
{
SAMPLE_RATE_x16 = 0, //Arithmetic
SAMPLE_RATE_x8 = 0x2, //Arithmetic
SAMPLE_RATE_x3 = 0x3 //Arithmetic
SAMPLE_RATE_x16 = 0x1, //Fractional
SAMPLE_RATE_x8 = 0x3, //Fractional
} SercomUartSampleRate;

typedef enum
Expand Down