Skip to content

Fix async serial port operation at 1200 baud, fix flush, fix data bits. #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Fix operation at 1200 baud. As per Table 24-2 of Atmel-42181G–SAM-D21…
…_Datasheet–09/2015,

constant in formula should be 65536, not 65535.  Also add 0.5 to round correctly to closest integer.
  • Loading branch information
TomKeddie committed Jan 1, 2016
commit 103ddee889529da6da1a5b16d466e3f99df7677e
6 changes: 3 additions & 3 deletions cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void SERCOM::initUART(SercomUartMode mode, SercomUartSampleRate sampleRate, uint
}

// 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));
// 65536 * ( 1 - sampleRateValue * baudrate / SystemCoreClock);
// add 0.5 to round up/down as appropriate
sercom->USART.BAUD.reg = 65536.0f * ( 1.0f - (float)(sampleRateValue) * (float)(baudrate) / (float)(SystemCoreClock)) + 0.5f;
}
}
void SERCOM::initFrame(SercomUartCharSize charSize, SercomDataOrder dataOrder, SercomParityMode parityMode, SercomNumberStopBit nbStopBits)
Expand Down