Simple program question about UART (SCB)

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

cross mob
SaWa_284216
Level 4
Level 4

 Okay so I have an extremely simple program, all it does it shoot an array of chars out of the UART. Before it starts communicating it sends a digital line high, then once it's done it makes it low again.

   

The project is attached but here it is for anyone who wants a quick scan.

   

 

   

   

It is straight forwards enough, as far as I can tell, there is no way that the line can go to zero until the UART has finished sending every one of its bytes. However the reality is much different.

   

   

 

   

If you look the green channel is the UART TX line and the yellow line is the lineDriver. If you notice the line goes high just before transmitting as you could expect, however it then goes immediately low before all the chars have finished sending. 

I think that the UART is operating asynchronously from the C code, it is just taking the inputs from the for loop and then sending them at a later timer. Does anyone know how to force it to run synchronously? maybe there is a status bit I can check for?

0 Likes
9 Replies
lock attach
Attachments are accessible only for community members.
SaWa_284216
Level 4
Level 4

oops forgot to attach the project

   

This is all on the psoc 4245-axi483 by the way..

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

Your Tx buffer is sized at 8, so the for loop is filling that up rapidly

   

(as long as buss is available, write is blocking pending buss availability).

   

 

   

So essentially the for loop completes early and UART finishes later.

   

 

   

So load buffer then start UART and or use  ISR to indicate Tx buffer empty.

   

Latter means you enable that ISR carefully to insure it does not fire early.

   

 

   

Regards, Dana.

   

 

   

 

   

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

When you wait for all characters transmitted and THEN set the line low, all would be fine. The function UARTPutchar() stores the characters in a buffer and only blocks when the buffer is full.

   

With UART_ReadTxStatus() you can see if the FIFO is empty and you can see if the last byte is transmitted successfully.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Image did not post.

   

 

   

Forgot to mention, in ISR flip pin low.

   

 

   

Image attached.

0 Likes
SaWa_284216
Level 4
Level 4

 Okay thanks for the replies but I am a bit confused. 

   

Bob you UART_ReadTxStatus(); function is unvailable to me it seems, it doesn't come up on autocomplete.

   

danadak are you saying that I need to increase my buffer size, and then set a tx empty interrupt. If so does this interrupt not just fire continuously while I am not transmitting, like before I even get to my UART code?

Also in your example jpeg you used an internal interrupt, I am not sure what to do with these, I have only used external ones before. 

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

Sorry, I was at the UDB-Component.

   

 

   

Internal interrupts are INTERNAL to the module and keep it working. In your example it cares for sending the next availlable character from the buffer to the Tx register (from which it is transmitted bit-by-bit). When transmitted an interrupt is fired (when enabled) so you have the chance to count the transmitted characters. When done set your line to "low".

   

 

   

Bob

0 Likes
Anonymous
Not applicable

since you are sending a byte at a time the PutChar function is simply filling the TX buffer and returning not waiting for the transmission actually completing. Unfortunatelly you can´t reduce the TX buffer bellow 8.

   

You could use  SCB_SpiUartGetTxBufferSize() to find out if the TX buffer is empty  and can wait intill it is. Although I'm not sure if it returns after the last bit has been succefukly transmitted or when it is picket from the buffer for transmission.

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

The Tx ISR fires when Tx buff is empty, so if all you send <= buffer size, you get one

   

ISR, then you disable it in ISR until ready to send again. If you get more than one, char

   

string exceeds bufffer size, code that to ignore the first N - 1 ISRs.

   

 

   

Note you can code

   

char response[] ={  'a', 'b', 'c', 'd', 'e', 'f', 'g', '/0' };

   

and use putstring to send the whole string. ISR notes still pertainent from above.

   

 

   

Regards, Dana.

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

Keep in mind you know how many chars you will be sending, hence

   

how many ISRs you are going to get until the last one, depending on

   

buffer size.

   

 

   

Regards, Dana.

0 Likes