- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.