diff --git a/port/ez430-rf2560/src/hal_uart_dma.c b/port/ez430-rf2560/src/hal_uart_dma.c index 9147312b4..d79ced130 100755 --- a/port/ez430-rf2560/src/hal_uart_dma.c +++ b/port/ez430-rf2560/src/hal_uart_dma.c @@ -265,17 +265,23 @@ static inline void hal_uart_dma_disable_rx(void){ P1OUT |= BIT3; // = 1 - RTS high -> stop } -// int used to indicate a request for more new data void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len){ - - UCA2IE &= ~UCRXIE ; // disable RX interrupts + // disable RX interrupts + UCA2IE &= ~UCRXIE ; rx_buffer_ptr = buffer; bytes_to_read = len; - - UCA2IE |= UCRXIE; // enable RX interrupts - hal_uart_dma_enable_rx(); // enable receive + // check if byte already received + int pending = UCA2IFG & UCRXIFG; + + // enable RX interrupts - will trigger ISR below if byte pending + UCA2IE |= UCRXIE; + + // if byte was pending, ISR controls RTS + if (!pending) { + hal_uart_dma_enable_rx(); + } } void hal_uart_dma_set_sleep(uint8_t sleep){ @@ -305,6 +311,7 @@ void usbRxTxISR(void){ ++rx_buffer_ptr; --bytes_to_read; if (bytes_to_read > 0) { + hal_uart_dma_enable_rx(); return; } P1OUT |= BIT3; // = 1 - RTS high -> stop diff --git a/port/msp-exp430f5438-cc2564b/src/hal_uart_dma.c b/port/msp-exp430f5438-cc2564b/src/hal_uart_dma.c index 9d336e4d1..8a2ce7996 100755 --- a/port/msp-exp430f5438-cc2564b/src/hal_uart_dma.c +++ b/port/msp-exp430f5438-cc2564b/src/hal_uart_dma.c @@ -265,17 +265,23 @@ static inline void hal_uart_dma_disable_rx(void){ P1OUT |= BIT4; // = 1 - RTS high -> stop } -// int used to indicate a request for more new data void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len){ - - UCA2IE &= ~UCRXIE ; // disable RX interrupts + // disable RX interrupts + UCA2IE &= ~UCRXIE ; rx_buffer_ptr = buffer; bytes_to_read = len; - - UCA2IE |= UCRXIE; // enable RX interrupts - hal_uart_dma_enable_rx(); // enable receive + // check if byte already received + int pending = UCA2IFG & UCRXIFG; + + // enable RX interrupts - will trigger ISR below if byte pending + UCA2IE |= UCRXIE; + + // if byte was pending, ISR controls RTS + if (!pending) { + hal_uart_dma_enable_rx(); + } } void hal_uart_dma_set_sleep(uint8_t sleep){ @@ -305,6 +311,7 @@ void usbRxTxISR(void){ ++rx_buffer_ptr; --bytes_to_read; if (bytes_to_read > 0) { + hal_uart_dma_enable_rx(); return; } P1OUT |= BIT4; // = 1 - RTS high -> stop diff --git a/port/msp430f5229lp-cc2564b/src/hal_uart_dma.c b/port/msp430f5229lp-cc2564b/src/hal_uart_dma.c index 4d7a630d8..63f515c28 100755 --- a/port/msp430f5229lp-cc2564b/src/hal_uart_dma.c +++ b/port/msp430f5229lp-cc2564b/src/hal_uart_dma.c @@ -278,17 +278,23 @@ static inline void hal_uart_dma_disable_rx(void){ RTS_OUT |= RTS_PIN; // = 1 - RTS high -> stop } -// int used to indicate a request for more new data void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len){ - - UCA0IE &= ~UCRXIE ; // disable RX interrupts + // disable RX interrupts + UCA0IE &= ~UCRXIE; rx_buffer_ptr = buffer; bytes_to_read = len; + // check if byte already received + int pending = UCAIFG & UCRXIFG; + + // enable RX interrupts - will trigger ISR below if byte pending UCA0IE |= UCRXIE; // enable RX interrupts - hal_uart_dma_enable_rx(); // enable receive + // if byte was pending, ISR controls RTS + if (!pending) { + hal_uart_dma_enable_rx(); + } } void hal_uart_dma_set_sleep(uint8_t sleep){ @@ -318,6 +324,7 @@ void usbRxTxISR(void){ ++rx_buffer_ptr; --bytes_to_read; if (bytes_to_read > 0) { + hal_uart_dma_enable_rx(); return; } RTS_OUT |= RTS_PIN; // = 1 - RTS high -> stop