UART complete before continuing

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

cross mob
lock attach
Attachments are accessible only for community members.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Is there a command that can send data but not continue until all data has been sent out UART?

   

In my code below, the UART data is sent After the EN goes low again. I want to have 10ms of EN high, then send the data byte and then have EN low. However, the EN goes high and low and then data appears on port pin. I also tried WriteTXData function. Attached is copy of the component layout on workspace. The required output is 125 kHz carrier for 10ms followed by ASK modulated carrier. The enable pin controls external hardware and should enable the chip when carrier and data sent and then go low. Thanks

   

    UART_Start();

   

    for(;;)

   

    {

   

       EN_Write(1);  //Start Carrrier

   

       CyDelay(10);

   

       UART_PutChar(0x55);  //Send Modulated data

   

       EN_Write(0);

   

       CyDelay(100);

   

    }

   

}

   
        
0 Likes
5 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You can always use a LUT to create a state machine to

   

sequence operations and check for completion, etc....

   

 

   

    

   

          

   

http://www.cypress.com/?rID=44402     AN62510 - Implementing State Machines with PSoC® 3, PSoC 4, and PSoC 5LP

   

http://www.cypress.com/?rID=52365     State machines using LUTs Video

   

 

   

Regards, Dana.

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

You can use UART_ReadtxStatus() to check for an empty Tx FIFO.

   

(Actually PutChar() is blocking, but in blocks only when the Tx FIFO is full, and its 4 bytes...)

0 Likes
Anonymous
Not applicable

you need to wait for BOTH fifo empty and transmit complete. the fifo can hold upto 4 bytes and the 'shift register' for output is a separate byte. so you have to have the fifo empty AND the last bit shifted out.

   

 

   

uint8 UART_ReadTxStatus(void)
Description: Reads the status register for the TX portion of the UART.
Parameters: void
Return Value: uint8: Contents of the TX Status register
Value Description
UART_TX_STS_COMPLETE If set, indicates byte was transmitted
successfully
UART_TX_STS_FIFO_EMPTY If set, indicates the TX FIFO is empty
UART_TX_STS_FIFO_FULL If set, indicates the TX FIFO is full
UART_TX_STS_FIFO_NOT_FULL If set, indicates the FIFO is not full
Side Effects: This function reads the TX status register, which is cleared on read.

   

 

   

-Ed

0 Likes
Anonymous
Not applicable

 Here's some code that I used in a PSoC3 - should also work in a PSoC4. I set fUARTTransmitActive to TRUE whenever I transmit anything. SleepFunc() only gets called after everything is completely transmitted.

   

Regards,

   

Kris

   

/* Read our TX status byte to make sure we don't sleep when still transmitting data */
bTXStatus = UART_1_ReadTxStatus(); /* Some of these bits clear on read, so just read once before checking! */

   


/* Here we need to do some checking to make sure it is OK to go to sleep. We want to wait until any
* serial transmit has been completed.
* Here are the conditions that need to be satisfied:
* 1. UART_1_GetTxBufferSize() == 0: We don't have any data in the transmit buffer which has not been loaded
* into the UART FIFO.
* 2. bTXStatus & UART_1_TX_STS_FIFO_EMPTY: The UART TX FIFO is empty
* 3. !((fUARTTransmitActive == TRUE) && !(bTXStatus & UART_1_TX_STS_COMPLETE)) : If we didn't transmit this
* wake cycle (fUARTTransmitActive == FALSE), we can safely go to sleep. If we did transmit this cycle and
* TX complete is set (i.e. byte has completely transmitted), we can safely go to sleep. We cannot go to
* sleep if we did transmit this cycle and TX complete is not set (i.e. byte has not completely transmitted).
* NOTE that we can't just simply check TX complete, since it won't be set if we didn't transmit this cycle
* (but it would be OK to go to sleep in that case).
*/

if ((UART_1_GetTxBufferSize() == 0 ) && (bTXStatus & UART_1_TX_STS_FIFO_EMPTY) && !((fUARTTransmitActive == TRUE) && !(bTXStatus & UART_1_TX_STS_COMPLETE)))
{
fUARTTransmitActive = FALSE; /* Reset flag before sleep */
SleepFunc();
}

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

If its really just about a single byte, checking the transmit state might be enough (because the byte is starting to be send as soon as it got put into the transmit buffer).

0 Likes