@@ -76,7 +76,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
76
76
obj -> uart -> TXD = 0 ;
77
77
78
78
obj -> index = 0 ;
79
-
79
+
80
80
obj -> uart -> PSELRTS = RTS_PIN_NUMBER ;
81
81
obj -> uart -> PSELTXD = tx ; //TX_PIN_NUMBER;
82
82
obj -> uart -> PSELCTS = CTS_PIN_NUMBER ;
@@ -162,20 +162,14 @@ extern "C" {
162
162
#endif
163
163
void UART0_IRQHandler ()
164
164
{
165
- if ((NRF_UART0 -> INTENSET & UART_INTENSET_TXDRDY_Msk ) && NRF_UART0 -> EVENTS_TXDRDY )
166
- {
167
- uart_irq (1 , 0 );
168
-
169
- /* Explicitly clear TX flag to prevent interrupt from firing
170
- immediately after returning from ISR. This ensures that the
171
- last interrupt in a transmission sequence is correcly handled.
172
- */
173
- NRF_UART0 -> EVENTS_TXDRDY = 0 ;
174
- }
175
- else if ((NRF_UART0 -> INTENSET & UART_INTENSET_RXDRDY_Msk ) && NRF_UART0 -> EVENTS_RXDRDY )
176
- {
177
- uart_irq (2 , 0 );
165
+ uint32_t irtype = 0 ;
166
+
167
+ if ((NRF_UART0 -> INTENSET & 0x80 ) && NRF_UART0 -> EVENTS_TXDRDY ) {
168
+ irtype = 1 ;
169
+ } else if ((NRF_UART0 -> INTENSET & 0x04 ) && NRF_UART0 -> EVENTS_RXDRDY ) {
170
+ irtype = 2 ;
178
171
}
172
+ uart_irq (irtype , 0 );
179
173
}
180
174
181
175
#ifdef __cplusplus
@@ -245,24 +239,11 @@ int serial_getc(serial_t *obj)
245
239
246
240
void serial_putc (serial_t * obj , int c )
247
241
{
248
- /* In interrupt mode, send character immediately. Otherwise, block until
249
- UART is ready to receive next character before sending.
250
-
251
- The TXDRDY flag is cleared in interrupt handler to ensure that it is
252
- cleared even if there are no more characters to send.
253
- */
254
- if (NRF_UART0 -> INTENSET & UART_INTENSET_TXDRDY_Msk )
255
- {
256
- obj -> uart -> TXD = (uint8_t )c ;
242
+ while (!serial_writable (obj )) {
257
243
}
258
- else
259
- {
260
- while (!serial_writable (obj )) {
261
- }
262
244
263
- obj -> uart -> EVENTS_TXDRDY = 0 ;
264
- obj -> uart -> TXD = (uint8_t )c ;
265
- }
245
+ obj -> uart -> EVENTS_TXDRDY = 0 ;
246
+ obj -> uart -> TXD = (uint8_t )c ;
266
247
}
267
248
268
249
int serial_readable (serial_t * obj )
0 commit comments