- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I got a UART transmission block working, sending 4 bytes at a time but the logic i'm using is actuallly not making a lot of sense to me, even though it works.
I was checking if the transmission status was FIFO not full, but what really makes sense is to check if the FIFO is empty so I can immediatly load it with the 4 bytes to send. When I do this, however, it never goes into the if, it's always false even if right before checking it I place the clearTXBuffer and I don't understand why.
Does anyone have any idea? Am I understanding the functioning wrong? I've read the datasheet some 3 or 4 times and this is what I could understand from it.
Thanks.
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
UART_1_ReadTxStatus() returns a bit pattern indicating different states that have happened (see datasheet of the UART you are using).
Try
if(UART_1_ReadTxStatus & UART_1_TX_STS_EMPTY){
...
}
which will be true when the EMPTY bit is set.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Pedro,
Could you please share your project file or code snippet focusing on your question? Also mention the device you're using.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bragadeesh
Here is the infinite loop snippet with the function:
for(;;)
{
temp_read=read_temperature(); // returns a float with the temperature
voltage_read = convert_current();
//current = (voltage_read-2.5)/current_sensitivity;
real_voltage=convert_voltage();
if(temp_read != -1000){ //reading of temp was correct
memcpy(&tempFloatToArray, &temp_read, sizeof(tempFloatToArray)); //transforms the float into a char array with 4 bytes
if(UART_1_ReadTxStatus() != UART_1_TX_STS_FIFO_FULL){ //if(UART_1_ReadTxStatus() != UART_1_TX_STS_FIFO_NOT_FULL){
for(j=0;j<sizeof(tempFloatToArray);j++){
UART_1_WriteTxData(tempFloatToArray
); }
}
clear_dataBuf();
}
CyDelay(125u);
}
What I'm talking about is line 12. It works if I do it like it is in the snippet, but it doesnt if I do
if(UART_1_ReadTxStatus == UART_1_TX_STS_EMPTY){
...
}
I just don't understand why. How does it put the 4 bytes of data I have in the 4 byte tx buffer if it's not even empty? I mean it works, it's just that I need to comment and justify the code I developed and I'm honestly not understanding why it even works at all.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
UART_1_ReadTxStatus() returns a bit pattern indicating different states that have happened (see datasheet of the UART you are using).
Try
if(UART_1_ReadTxStatus & UART_1_TX_STS_EMPTY){
...
}
which will be true when the EMPTY bit is set.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Bob, it works when I use the '&' logic operator like you posted it works fine, but I was doing it like this:
if(UART_1_ReadTxStatus == UART_1_TX_STS_EMPTY){
...
}
Which didn't work, i'm assuming because of the way the uart component checks and provides the buffer status.
Thanks for the help once again!