4 Replies Latest reply on Mar 11, 2015 2:20 PM by jota_1939431 Branched from an earlier discussion.

    Problem with UART watermarks

    madmax

      Arvinds,


      I checked the thread: UART Routines  and the code you posted there.

      I did 2 testes. In both tests I send 10 bytes to PUART when button is pressed (on TAG3 board):


      #define W_MARK 0

      void hello_sensor_interrupt_handler(UINT8 value)

      {

          if (value&0x01)

        {

              // Set watermark

              // Max watermark level is P_UART_WATER_MARK_TX_LEVEL_HIGHEST ( = 15)

              P_UART_WATER_MARK_TX_LEVEL( W_MARK );

       

              if(P_UART_TX_FIFO_IS_EMPTY())

              {

                    puart_synchronousWrite("12345678\n\r", 10) ;

                    // Enable the TX interrupt. Callback registered with puart_txCb will be invoked when all bytes

                    // have been transmitted.

                    P_UART_INT_ENABLE |= P_UART_ISR_TX_FAE_MASK;

              }

          }

      }

       

      In puart_tx_callback function I check if TX FIFO is empty:


      void puart_tx_callback(void)

      {

          // Clear interrupt state

          P_UART_INT_CLEAR(P_UART_ISR_TX_FAE_MASK);

       

          // TX FIFO is empty now. So send another at most 16 bytes here if required,

          // set new watermark (if not 0) and re-enable TX interrupt.

       

          // check is TX FIFO is really empty

          if(P_UART_TX_FIFO_IS_EMPTY())

              ble_trace0(">>>>>> TX FIFO empty\n\r");

          else

              ble_trace0(">>>>>> TX FIFO not empty !!!\n\r");

      }



      Test 1.

      #define W_MARK 0

      puart_tx_callback reports that TX FIFO is NOT empty !!! why ????


      Test 2.

      #define W_MARK 15

      Since we send only 10 bytes puart_tx_callback should never be called  (10 < 15)

      In fact puart_tx_callback IS called !!! why ????

       

      Attached, you will find the test code based on hello_sensor app.