Circular buffer of UART with HardwareFlow Control for CY8CKIT-041-40XX

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

cross mob
YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

Hello,

I am trying RX and TX loopback communication of Circular buffer UART with hardware flow control under CY8CKIT-041-40XX.

By pressing the switch, specific character strings are output from TX of UART and input to RX by loopback connection.

CTS and RTS are also loopback connected.The strings received by RX are output from SW TxUART to the terminal software of PC.

pastedImage_3.png

pastedImage_0.png

When the TX and RX buffers are set to FIFO size and "RX FIFO not empty" of interrupt is checked, the following interrupt handlers"UartIntHandler" are operating without problems.

pastedImage_0.png

pastedImage_1.png

On the other hand, if I use Circular buffer with RX polling processing because I do not know the method of reception interrupt, I will continue to wait for the TX buffer to be ”not full" with the following code.

pastedImage_0.png

pastedImage_1.png

Please tell me how to receive RX data with interrupt handler.

Best regards,

Yocchi

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hi YoIs_1298666​,

Thank you for the detailed explanation. I understand your question now.

When you are using software buffer, the UART ISR uses the RX FIFO NOT EMPTY interrupt to transfer the bytes from the hardware FIFO to the software buffer. If you still want an interrupt based byte reception (with software buffer), you can make use of the callback function SCB_UART_SPI_UART_ISR_ExitCallback(). This callback function is executed at the end of the internal UART ISR. See UART_SPI_UART_INT.c

The usage of this call back is available in SCB component datasheet - Pg182

https://www.cypress.com/file/408071/download

Refer PSoC Creator User guide on how to add this component provided callback function into your project - Pg no 66

https://www.cypress.com/file/137441/download

I've attached a sample project for your reference. Let us know if you have questions.

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes
6 Replies
YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

Hello,

Of course, I understand that it is good to execute UART_SpiUartWriteTxData so that the TX Circular buffer

does not become full and continue RX reception.

Even if the TX Circular buffer is full, is there an interrupt processing method for RX reception?

Best regards,

Yocchi

0 Likes

Hi YoIs_1298666​,

Could you please attach the project file or source code of what you are trying to achieve? You had mentioned about some code in your post but I do not see any code in your response?

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes
lock attach
Attachments are accessible only for community members.

Hi YoIs_1298666​,

Thank you for the detailed explanation. I understand your question now.

When you are using software buffer, the UART ISR uses the RX FIFO NOT EMPTY interrupt to transfer the bytes from the hardware FIFO to the software buffer. If you still want an interrupt based byte reception (with software buffer), you can make use of the callback function SCB_UART_SPI_UART_ISR_ExitCallback(). This callback function is executed at the end of the internal UART ISR. See UART_SPI_UART_INT.c

The usage of this call back is available in SCB component datasheet - Pg182

https://www.cypress.com/file/408071/download

Refer PSoC Creator User guide on how to add this component provided callback function into your project - Pg no 66

https://www.cypress.com/file/137441/download

I've attached a sample project for your reference. Let us know if you have questions.

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Hello Bragadeesh-san,

This callback function is good.

But there are two proglems.

1. This callback function "UART_SPI_UART_ISR_ExitCallback()" uses both TX and RX interrupts.

     Try sending 500 bytes of data. You can see that it is in the TX and RX interrupts.

     The ExitCallback is called after clearing the interrupt source.

           UART_ClearTxInterruptSource(UART_INTR_TX_NOT_FULL);

           UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);

      I think that the following "if statement" judges the interrupt of TX and RX, but I think that I can not judge

      whether TX and RX entered the interrupt by using these.

           if (UART_CHECK_INTR_RX_MASKED(UART_INTR_RX_NOT_EMPTY)){...}

           if (UART_CHECK_INTR_TX_MASKED(UART_INTR_TX_NOT_FULL)){...}

2. The software buffer seems to fetch several bytes of data in one RX interrupt, so how much bytes should I

    read with "UART_SpiUartReadRxData()" in the callback function?

if I change like below, It can run well.

Do you have a better way?

pastedImage_0.png

pastedImage_1.png

Best regards,

Yocchi

0 Likes

Hi YoIs_1298666​,

We usually do not recommend modifying the generated source unless and other it is tested completely by the user.

Although you can still modify the generated source files, you can use the API UART_SpiUartGetRxBufferSize() that returns the no of bytes in the RX software buffer.

/* Reads data only if there is data to read */

    while(0u != UART_SpiUartGetRxBufferSize())

    {

            rxData = UART_SpiUartReadRxData();

    }


Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Hello Bragadeesh-san,

I agree with you.

Thank you very much.

Best regards,

Yocchi

0 Likes