@@ -50,9 +50,21 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
50
50
pinPeripheral (uc_pinRX, g_APinDescription[uc_pinRX].ulPinType );
51
51
pinPeripheral (uc_pinTX, g_APinDescription[uc_pinTX].ulPinType );
52
52
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;
56
68
}
57
69
58
70
sercom->initUART (UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate);
@@ -82,10 +94,9 @@ void Uart::IrqHandler()
82
94
rxBuffer.store_char (sercom->readDataUART ());
83
95
84
96
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
87
98
if (rxBuffer.availableForStore () < RTS_RX_THRESHOLD) {
88
- sercom-> disableReceiveCompleteInterruptUART () ;
99
+ *pul_outsetRTS = ul_pinMaskRTS ;
89
100
}
90
101
}
91
102
}
@@ -129,10 +140,9 @@ int Uart::read()
129
140
int c = rxBuffer.read_char ();
130
141
131
142
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
134
144
if (rxBuffer.availableForStore () > RTS_RX_THRESHOLD) {
135
- sercom-> enableReceiveCompleteInterruptUART () ;
145
+ *pul_outclrRTS = ul_pinMaskRTS ;
136
146
}
137
147
}
138
148
0 commit comments