Need to use more bytes from the UART tx buffer but can't understand how to use the interrupt

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

cross mob
Anonymous
Not applicable

Hello.

I need to send 5 bytes rather than the maximum of 4 that the tx buffer from the UART component allows. I already got it in TX mode but according to the datasheet, when you increase the size of the buffer an internal interrupt is automatically enabled. However, even after reading the datasheet 3 or 4 times, i don't understand how that interrupt works. I don't know what the different interrupt options in the component setup do:

pastedImage_1.png

I also don't know how to use this in my main.c code, do I need to add a new interrupt handler even though this is an internal interrupt? I would higly appreciate any sort of code example that deals with this so I could try and understand it cause right now i'm quite lost.

Thanks in advance

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

When you increase the buffers (RX, TX or both) an internal interrupt is used to maintain circular buffers for you.

Use the API GetTxBuffersize() to see how many bytes still need to get transmitted. Do not set the buffersize to match exactly your needed amount, be a bit generous. Use 20 or 80 bytes...

This is the easiest way, no isr component needed.

Bob

View solution in original post

6 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When you increase the buffers (RX, TX or both) an internal interrupt is used to maintain circular buffers for you.

Use the API GetTxBuffersize() to see how many bytes still need to get transmitted. Do not set the buffersize to match exactly your needed amount, be a bit generous. Use 20 or 80 bytes...

This is the easiest way, no isr component needed.

Bob

Anonymous
Not applicable

Thanks bob.marlowe​. Right now im using the WriteTxData from the API and my code is something like this:

if(UART_1_ReadTxStatus() != UART_1_TX_STS_FIFO_NOT_FULL){

                for(j=0;j<sizeof(data);j++){

                UART_1_WriteTxData(data);

                }

            }

So should I verify the Tx buffer before sending info, like this:

if((UART_1_ReadTxStatus() != UART_1_TX_STS_FIFO_NOT_FULL) && UART_1_GetTxBufferSize()==0){

                for(j=0;j<sizeof(data);j++){

                UART_1_WriteTxData(data);

                }

            }

?

Or should I use a function other than WriteTxData, like the PutChar?

0 Likes
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

As I understanding, you only need to extend the buffer size when you need, and you don't need to add a custom interrupt.

The Internal Tx interrupt ISR is automatically added to report the system to transmit the data from software buffer to fifo when the fifo is empty.

pastedImage_0.png

pastedImage_1.png

Hope it can make sense for you.

Anonymous
Not applicable

Thanks ring​.

However you don't seem to do any verification on the Tx buffer. From reading the datasheet, I understood that when using the WriteTxData function, you had to verify the state of the buffer because otherwise you could overwrite it. Any reason why you don't do it?

Thanks.

0 Likes

For ease of use:

Do not use WriteTxData().

Use PutChar() or PutString(). The checking for room in buffers is done by the APIs.

Check GetTxBufferSize() for zero to see if all bytes have been transmitted.

Bob

We should do verification on the Tx buffer when using API:    UART_1_WriteTxData(data).I make a mistake here, so sorry.

When I give you this code, I want to demonstrate if you want to extend the Tx buffer, you can use the component " buffer size", and when the fifo is empty, the internal interrupt will be triggered.

0 Likes