From 5ad078fa2d24b31a92b4a186e16b4053039eac9e Mon Sep 17 00:00:00 2001 From: Jonathan BAUDIN <jonathan.baudin@atmel.com> Date: Thu, 12 Jun 2014 15:27:50 +0200 Subject: [PATCH] Fixing UART (sercom0) --- cores/arduino/Uart.cpp | 11 +++++++---- cores/arduino/Uart.h | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp index 0d3abb98..0fc77541 100644 --- a/cores/arduino/Uart.cpp +++ b/cores/arduino/Uart.cpp @@ -2,11 +2,11 @@ #include "WVariant.h" #include "wiring_digital.h" -Uart::Uart(SERCOM *s, uint8_t pinRX, uint8_t pinTX) +Uart::Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX) { - sercom = s; - pinPeripheral(pinRX, g_APinDescription[pinRX].ulPinType); - pinPeripheral(pinTX, g_APinDescription[pinTX].ulPinType); + sercom = _s; + uc_pinRX = _pinRX; + uc_pinTX = _pinTX; } void Uart::begin(unsigned long baudrate) @@ -16,6 +16,9 @@ void Uart::begin(unsigned long baudrate) void Uart::begin(unsigned long baudrate, uint8_t config) { + pinPeripheral(uc_pinRX, g_APinDescription[uc_pinRX].ulPinType); + pinPeripheral(uc_pinTX, g_APinDescription[uc_pinTX].ulPinType); + sercom->initUART(UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate); sercom->initFrame(extractCharSize(config), LSB_FIRST, extractParity(config), extractNbStopBit(config)); sercom->initPads(UART_TX_PAD_2, SERCOM_RX_PAD_3); diff --git a/cores/arduino/Uart.h b/cores/arduino/Uart.h index b8c64880..a018b884 100644 --- a/cores/arduino/Uart.h +++ b/cores/arduino/Uart.h @@ -11,7 +11,7 @@ class Uart : public HardwareSerial { public: - Uart(SERCOM *s, uint8_t pinRX, uint8_t pinTX); + Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX); void begin(unsigned long baudRate); void begin(unsigned long baudrate, uint8_t config); void end(); @@ -29,6 +29,9 @@ class Uart : public HardwareSerial private: SERCOM *sercom; RingBuffer rxBuffer; + + uint8_t uc_pinRX; + uint8_t uc_pinTX; SercomNumberStopBit extractNbStopBit(uint8_t config); SercomUartCharSize extractCharSize(uint8_t config); -- GitLab