UART API bug in UART_GetByte()?

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

cross mob
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hello,

I'm using the UART API as follows:

while(0 == UART_1_GetRxBufferSize());
Receive = UART_1_GetByte();
if((Receive & 0xFF00) == 0) {
	*data = (char) (Receive & 0x00FF);
}

The UART component datasheet states for UART_GetByte():

Return Value: uint16: MSB contains status and LSB contains UART RX data. If the MSB is nonzero, an error has occurred.

I'm getting 0x20 for the MSB. Digging through the API sourcecode, it seems that bit 5 indicates that the FIFO is not empty (UART_1_RX_STS_FIFO_NOTEMPTY).
I wonder if I'm handling the return value wrong or if the API simply has a bug - I think it should mask out the FIFO not empty flag since if the FIFO still has data this is not an error 😄

Anyone can confirm this?

Regards

0 Likes
1 Solution
Arpit_S
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 250 sign-ins

Hi @RaAl_264636 

It is not an error. As you pointed out, this simply means FIFO still has data. It's an API description mistake, we will work on this to correct it.

Thanks & Regards

Arpit Srivastav

View solution in original post

0 Likes
7 Replies
Arpit_S
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 250 sign-ins

Hi,

Can you please tell which device are you working on? and which Development Environment you're working with? Is it ModusToolbox or PSoC Creator?

0 Likes

Hello @Arpit_S 

sorry, I forgot to mention it: I'm working on a CY8CKIT-059 (PSoC 5LP CY8C5888LTI) with PSoC Creator 4.4.

Regards

0 Likes
BiBi_1928986
Level 7
Level 7
First comment on blog 500 replies posted 250 replies posted

Hello.

The MSB is a status byte.  Don't read more into it than that.  Collectively, it contains both status flags and error flags.  If you want just the error flags, then mask off the other flags in your code.  Just be aware that several of these bits are "clear on read".

Caution:  If you add more UDB based logic to your design, don't count on MSB bit-5 to always represent UART_1_RX_STS_FIFO_NOTEMPTY.  The MSB status bit positions move around since this UART is based on UDB's.  You have to use the "defines" for the bit positions.  And, if there is more than 1 UART in the project, its MSB status bits can be arranged in different bit positions vs the other UART status bits.

I do agree though, the statement: If the MSB is nonzero, an error has occurred. is misleading.  Delete that statement and it will make better sense.

0 Likes

Good hint, I shouldn't use magic numbers - currently I'm using

(Receive & 0xDF00)

instead of the provided definitions for masking the FIFO not empty flag.
For the statement, I don't think it should be removed. Instead, the return value should exclude the flag.

Regards

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hello@Arpit_S ,

any news on this?

Regards

0 Likes
Arpit_S
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 250 sign-ins

Hi @RaAl_264636 

It is not an error. As you pointed out, this simply means FIFO still has data. It's an API description mistake, we will work on this to correct it.

Thanks & Regards

Arpit Srivastav

0 Likes

Hello @Arpit_S 

sounds good, thank you. Please discuss with the team if it makes sense to remove the flag from the return value. From my understanding of the API the function

UART_1_GetRxBufferSize()

should always be used before reading the FIFO, so this flag is redundant in the return value. That's just a suggestion.

Thank you for your help.

Regards