4 Replies Latest reply on Oct 5, 2017 12:22 PM by gogac_2790176

    Using UART component RX Interrupt - Tx Polling

      Hi all,

      I'm a newbie using Cypress platform and i'm currently developing an application where uses rs485 protocol, based on a UART component.

      I'm guessing if there's any possibility to use the UART interrupt for RX and using Tx in blocking and polling mode. I mean, i want to check that UART has sent all the data, by checking UART_INTR_TX_UART_DONE without interrupts. Here an example:



      Rs485_SendData( uint8_t *txbuf, uint16_t len ) {

      uint16_t btosend, bsent;  

          btosend = len;

          bsent = 0;


        while( btosend-- ) {

        UART_UartPutChar( *( txbuf + bsent ) );



           /* Here i want to check by polling if UART_INTR_TX_UART_DONE sets to enable Rx pin of driver */


          return bsent;


      Any suggest?

      Thanks in advance

        • 1. Re: Using UART component RX Interrupt - Tx Polling

          There is an easy solution: Let the component handle its interrupts.

          When the Rx and Tx buffers set to something larger than the internal FIFO size (let's say: 80 bytes) some internal routines will support sending and receiving data using interrupt handlers.

          You can check the completeness of the transfers using UART_GetRxBufferSize() or GetTxBufferSize() APIs. Returned is always the actual number of bytes residing in the buffer.

          When RxBufferSize() returns != 0 you can retrieve the bytes with the appropriate API.

          TxBufferSize() == 0 indicates no more bytes remain to be sent.



          • 2. Re: Using UART component RX Interrupt - Tx Polling

            Thanks for your fast response Bob!

            But when using rs485, i must to enable rx mode in transceiver just at the end of the UART shift register transmision, thus, polling RxBufferSize() is not enough for a proper operation. I would like to busy check both UART_DONE and UART_TX_FIFO_EMPTY register to be sure that the transmision was succeed.

            Could this be correct?

            /* Busy wait to transmit data from buffer to tx shift register */

            shile( ( UART_GetTxInterruptSource & UART_INTR_TX_EMPTY ) == 0 );

            /* Busy wait to transmit all shifted data */

            while( ( UART_GetTxInterruptSource & UART_INTR_TX_UART_DONE ) == 0 );

            /* Renable rs485 Rx mode */



            Thanks for your attention!



            • 3. Re: Using UART component RX Interrupt - Tx Polling

              Your code will work when you use UART_GetTxInterruptSource() (parentheses needed).

              Additionally you will need to reset the interrupt cause at end of your handler using UART_ClearTxInterruptSource().



              1 of 1 people found this helpful
              • 4. Re: Using UART component RX Interrupt - Tx Polling

                Thanks Bob,

                I finally got through interrupts! Thank for your reply!