How to use the UART_ReadTxStatus() function

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

   

 For my project I am using the UDB UART block. While going through the datasheet of the UART block, I came across the API UART_ReadTxStatus() which is used to read the status register for the TX of UART. I needed to write a function that "waits for the transmission of outgoing serial data to complete" similar to the Serial.flush() function of the Arduino.

   

I would like to obtain some more clarity about the UART_ReadTxStatus() function and its return parameters. From the datasheet, what I could gather was that the function returned the values UART_TX_STS_COMPLETE, UART_TX_STS_FIFO_EMPTY, UART_TX_STS_FIFO_FULL, UART_TX_STS_FIFO_NOT_FULL respectively depending on the contents of the transmit buffer.

   

So does this mean that the function returns the values 01hex, 02hex, 03hex and 04hex respectively depending on the above mentioned parameters?

   

Thanks,

   

Ganesh

0 Likes
1 Solution
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

COMPLETE and FIFO_EMPTY can be active at the same time. Its best to use the provided constants as bit masks and filter for the status you actually want to look for.

View solution in original post

0 Likes
13 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

COMPLETE and FIFO_EMPTY can be active at the same time. Its best to use the provided constants as bit masks and filter for the status you actually want to look for.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Ganesh,

   

the UART_ReadTxStatus() function returns the ORed value of all the active stati, so do not rely on values like 0x01 returned, but use constructs like

   

if(UART_ReadTxStatus() & UART_TX_STS_COMPLETE)

   

...

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I would like to use this very same function to achieve a flush before putting my BLE device to sleep. When I found this function, I assumed it would be in the standard UART library however I cannot seem to find it in any of my libraries. So something is amiss here. I searched Cypress website and nothing relevant came up other than more links to the community forum.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The names differ based on the component you use: SCB based or UDB based. The former does not deliver a state, but you can poll using UART_SpiUartGetRxBufferSize() to see how many bytes have been received yet.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks Bob for reply. Yes I'm using SCB mode. The issue I am trying to resolve is that my TX messages don't finish as system goes to sleep on next instruction. This is commonly resolved on other micros using a blocking TX flush routine to ensure all the bytes are cleared before continuing. Hence I thought UART_ReadTxStatus() & UART_TX_STS_COMPLETE would be my solution.

   

I'm looking at my UART block in topdesign config and I notice I have a number of interrupt configuration options available to me under UART advanced. Would any of these help me. Thought the "UART done" might work but then not sure whether I need to select Internal or External and then what next. This feels a little like reinventing the wheel as I am sure other people have solved this issue before.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Call UART_GetTxInterruptSource() and wait for UART_INTR_TX_UART_DONE set. Do not forget to call UART_Sleep() before sending the whole system asleep and UART_Wakeup() when back again.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks

0 Likes
Anonymous
Not applicable

I'm not geting UART_GetTxInterruptSource() to trigger a UART_INTR_TX_UART_DONE.

   

I've enabled interrupt routine using UART_EnableInt(); (I'm assuming this is required). I've enabled global interrupts too.

   

For testing I'm sending a long string UART_UartPutString("Hello this is a new test string! 123567890\r\n");

   

I am then simply waiting for UART_GetTxInterruptSource() to return UART_INTR_TX_UART_DONE before moving to next routine but this never fires.

   

I think part of my problem is knowing how to script the interrupt routines. I've set up my UART SCB with internal interrupts. In my c code I am not really sure how to handle this correctly.

   

Any advice?

   

Thanks

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

This is a simple test. Code resides in main().

   

    uint8 xx = 0;
    for (xx = 0; xx < 5; xx++) {
        UART_UartPutString("The quick brown fox jumps over the lazy dog! 123567890\r\n");
        UART_Sleep();
        CyDelay(1000);
        UART_Wakeup();
    }

   

At the moment when code is uploaded and executed the string gets truncated. So I'm looking to use Interrupt to check when UART TX is done before calling UART_Sleep(). I cannot get this to work.

   

I've set up my UART SCB component to have an internal interrupt and ticked the "UART done" as Interrupt source.

   

 I added the following code before the routine shown above:

   

    UART_Start();
    UART_SetCustomInterruptHandler( UART_ISR_Handler );
    UART_SetTxInterruptMode(UART_INTR_TX_UART_DONE);
    UART_EnableInt();

   

    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
    

   

My custom interrupt handler routine

   

CY_ISR ( UART_ISR_Handler)
{
}

   

This is not getting triggered as far as I can tell. If I place the UART_Sleep();CyDelay(1000);UART_Wakeup(); in this function nothing happens.

   

Any tips greatly appreciated.

   

 

   

I've attached the workspace bundle. 

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Try this one. You will have to change back to your device.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

This tread saved my day.

   

Thanks

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Fine when that has been of any assistance.

   

 

   

Bob

0 Likes