@@ -50,9 +50,21 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
5050 pinPeripheral (uc_pinRX, g_APinDescription[uc_pinRX].ulPinType );
5151 pinPeripheral (uc_pinTX, g_APinDescription[uc_pinTX].ulPinType );
5252
53- if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3 && uc_pinRTS != NO_RTS_PIN && uc_pinCTS != NO_CTS_PIN) {
54- pinPeripheral (uc_pinRTS, g_APinDescription[uc_pinRTS].ulPinType );
55- pinPeripheral (uc_pinCTS, g_APinDescription[uc_pinCTS].ulPinType );
53+ if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3) {
54+ if (uc_pinCTS != NO_CTS_PIN) {
55+ pinPeripheral (uc_pinCTS, g_APinDescription[uc_pinCTS].ulPinType );
56+ }
57+ }
58+
59+ if (uc_pinRTS != NO_RTS_PIN) {
60+ pinMode (uc_pinRTS, OUTPUT);
61+
62+ EPortType rtsPort = g_APinDescription[uc_pinRTS].ulPort ;
63+ pul_outsetRTS = &PORT->Group [rtsPort].OUTSET .reg ;
64+ pul_outclrRTS = &PORT->Group [rtsPort].OUTCLR .reg ;
65+ ul_pinMaskRTS = (1ul << g_APinDescription[uc_pinRTS].ulPin );
66+
67+ *pul_outclrRTS = ul_pinMaskRTS;
5668 }
5769
5870 sercom->initUART (UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate);
@@ -82,10 +94,9 @@ void Uart::IrqHandler()
8294 rxBuffer.store_char (sercom->readDataUART ());
8395
8496 if (uc_pinRTS != NO_RTS_PIN) {
85- // if there is NOT enough space in the RX buffer,
86- // diable the receive complete interrupt
97+ // RX buffer space is below the threshold, de-assert RTS
8798 if (rxBuffer.availableForStore () < RTS_RX_THRESHOLD) {
88- sercom-> disableReceiveCompleteInterruptUART () ;
99+ *pul_outsetRTS = ul_pinMaskRTS ;
89100 }
90101 }
91102 }
@@ -129,10 +140,9 @@ int Uart::read()
129140 int c = rxBuffer.read_char ();
130141
131142 if (uc_pinRTS != NO_RTS_PIN) {
132- // if there is enough space in the RX buffer,
133- // enable the receive completer interrupt
143+ // if there is enough space in the RX buffer, assert RTS
134144 if (rxBuffer.availableForStore () > RTS_RX_THRESHOLD) {
135- sercom-> enableReceiveCompleteInterruptUART () ;
145+ *pul_outclrRTS = ul_pinMaskRTS ;
136146 }
137147 }
138148
0 commit comments