UART_ReadRxStatus always 0?

A catchall for PSoC3 discussions not captured by the other forums.

Moderator: ericb

UART_ReadRxStatus always 0?

Postby Turtle » Wed Sep 04, 2013 7:08 am

Hi,

in my project UART_ReadRxStatus always returns 0 although I am sure that there is data in the buffer.
This makes it impossible to watch the RxStatus and react as soon as data comes
(I know about interrupt routines...)
What is wrong?

Code snippet:
//at this point I am sure that data is in the buffer
ack = UART_DISPLAY_ReadRxStatus(); //returns 0, should be UART_RX_STS_FIFO_NOTEMPTY
ack = UART_DISPLAY_GetRxBufferSize(); //returns 1 (1 byte received)
ack = UART_DISPLAY_ReadRxData(); //returns 0x06, the value I expect
ack = UART_DISPLAY_ReadRxStatus(); //returns 0
ack = UART_DISPLAY_GetRxBufferSize(); //returns 0 (byte was read)
Processor: CY8C3666AXI-052

Any ideas?
Turtle
Turtle
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 19
Joined: Mon Apr 21, 2008 6:50 am

Re: UART_ReadRxStatus always 0?

Postby bobmarlowe » Wed Sep 04, 2013 7:29 am

Probably the "Internal Interrupt" is switched on because your receive-buffer is larger than 4 bytes. The status bits are red in the interrupt-handler and the byte is put into your receive-buffer.
You have two choices:
1. use the GetRxBufferSize() function to test whether there was something received
or 2. Write your own interrupt handler and put all received bytes into a circular buffer.


Happy coding
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: UART_ReadRxStatus always 0?

Postby Turtle » Fri Sep 06, 2013 2:15 am

Thank you, Bob,

the approach with GetRxBufferSize works fine.
I did not understand that the NOTEMPTY flag is not available
because of the interrupt handler.

Regards,
Turtle
Turtle
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 19
Joined: Mon Apr 21, 2008 6:50 am

Re: UART_ReadRxStatus always 0?

Postby bobmarlowe » Fri Sep 06, 2013 3:05 am

The explanation for the missing NotEmpty-flag is:
main() running
Internal interrupt handler takes over control when a byte is reived.
Handler reads status, thus clearing any pendent error-bits
Handler reads off the received data-byte and stores it in the buffer. This clears the NotEmpty-flag
Handler returns from interrupt.
main() continues execution

So there seems to be no time for main() to check successfully for a NotEmpty status.

As I stated before, writing your own interrupt-handler (by keeping the buffersize to four (4) and enabling an Rx-int) is a very good exercise since the method of a "Circular Buffer" is commonly used and can help to understand the functioning of interrupt and buffering as well as writing APIs to present the needed information to main().

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany


Return to “%s” PSoC3 General

Who is online

Users browsing this forum: No registered users and 1 guest