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
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
2 changes: 1 addition & 1 deletion cores/arduino/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class HardwareSerial : public Stream
{
public:
virtual void begin(unsigned long);
virtual void begin(unsigned long baudrate, uint8_t config);
virtual void begin(unsigned long baudrate, uint16_t config);
virtual void end();
virtual int available(void) = 0;
virtual int peek(void) = 0;
Expand Down
12 changes: 6 additions & 6 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 Expand Up @@ -112,7 +112,7 @@ void SERCOM::enableUART()
void SERCOM::flushUART()
{
// Wait for transmission to complete
while(sercom->USART.INTFLAG.bit.DRE != SERCOM_USART_INTFLAG_DRE);
while(!sercom->USART.INTFLAG.bit.TXC);
}

void SERCOM::clearStatusUART()
Expand Down Expand Up @@ -168,8 +168,8 @@ uint8_t SERCOM::readDataUART()

int SERCOM::writeDataUART(uint8_t data)
{
//Flush UART buffer
flushUART();
// Wait for data register to be empty
while(!isDataRegisterEmptyUART());

//Put data into DATA register
sercom->USART.DATA.reg = (uint16_t)data;
Expand Down
8 changes: 4 additions & 4 deletions cores/arduino/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void Uart::begin(unsigned long baudrate)
begin(baudrate, (uint8_t)SERIAL_8N1);
}

void Uart::begin(unsigned long baudrate, uint8_t config)
void Uart::begin(unsigned long baudrate, uint16_t config)
{
pinPeripheral(uc_pinRX, g_APinDescription[uc_pinRX].ulPinType);
pinPeripheral(uc_pinTX, g_APinDescription[uc_pinTX].ulPinType);
Expand Down Expand Up @@ -93,7 +93,7 @@ size_t Uart::write(const uint8_t data)
return 1;
}

SercomNumberStopBit Uart::extractNbStopBit(uint8_t config)
SercomNumberStopBit Uart::extractNbStopBit(uint16_t config)
{
switch(config & HARDSER_STOP_BIT_MASK)
{
Expand All @@ -106,7 +106,7 @@ SercomNumberStopBit Uart::extractNbStopBit(uint8_t config)
}
}

SercomUartCharSize Uart::extractCharSize(uint8_t config)
SercomUartCharSize Uart::extractCharSize(uint16_t config)
{
switch(config & HARDSER_DATA_MASK)
{
Expand All @@ -126,7 +126,7 @@ SercomUartCharSize Uart::extractCharSize(uint8_t config)
}
}

SercomParityMode Uart::extractParity(uint8_t config)
SercomParityMode Uart::extractParity(uint16_t config)
{
switch(config & HARDSER_PARITY_MASK)
{
Expand Down
8 changes: 4 additions & 4 deletions cores/arduino/Uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Uart : public HardwareSerial
public:
Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX);
void begin(unsigned long baudRate);
void begin(unsigned long baudrate, uint8_t config);
void begin(unsigned long baudrate, uint16_t config);
void end();
int available();
int peek();
Expand All @@ -51,7 +51,7 @@ class Uart : public HardwareSerial
SercomRXPad uc_padRX;
SercomUartTXPad uc_padTX;

SercomNumberStopBit extractNbStopBit(uint8_t config);
SercomUartCharSize extractCharSize(uint8_t config);
SercomParityMode extractParity(uint8_t config);
SercomNumberStopBit extractNbStopBit(uint16_t config);
SercomUartCharSize extractCharSize(uint16_t config);
SercomParityMode extractParity(uint16_t config);
};