Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > using the usart component

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



using the usart component
Moderator:
JFMD

Post Reply
Follow this topic



using the usart component

firehopper posted on 21 Jan 2013 6:14 PM PST
Top Contributor
25 Forum Posts

it says in the usart_getbyte(); thing..

that msb is status, and lsb is the actual byte.

 

how can I seperate that? 

 

Basicly I have,

 

uint16 rxdata

rxdata = rx_GetByte();

 

the device outputs 8 pairs of bytes,

0000 01ff 01ff 01ff 01ff 01ff 01ff 01ff

I need to find the 0000's as thats a framing marker to tell me the start of the output, then each pair after is one channel of data




Re: using the usart component

Bob Marlowe posted on 22 Jan 2013 01:19 AM PST
Top Contributor
1768 Forum Posts

That is basic C-workmanship:

uint8 UpperByte,LowerByte;
uint16 USARTWord;

USARTWord = USART_GetByte();

UpperByte = (uint8)(USARTWord >> 8); // Shift right

LowerByte = (uint8)(USARTWord & 0x00ff); // Mask off upper bits

 

 

Happy coding

Bob

 

 



Re: using the usart component

firehopper posted on 22 Jan 2013 06:19 AM PST
Top Contributor
25 Forum Posts

awesome, thanks :) 

 



Re: using the usart component

firehopper posted on 22 Jan 2013 08:50 AM PST
Top Contributor
25 Forum Posts

now, just in case I need to.. how can I recombine 2 uint8's into a uint16? 

 

I may need to do this later. I dont know yet.

but I might as well ask how right now.. :> 

 



Re: using the usart component

Bob Marlowe posted on 22 Jan 2013 09:44 AM PST
Top Contributor
1768 Forum Posts

well, something like

 

USARTWord = (uint16)(UpperByte << 8) | (uint16)LowerByte;

 

Happy coding

Bob



Re: using the usart component

danaaknight posted on 22 Jan 2013 11:13 AM PST
Top Contributor
1773 Forum Posts

Bob, should this -

 

USARTWord = (uint16)(UpperByte << 8) | (uint16)LowerByte;

 

be this -

 

USARTWord = (  ( uint16 ) UpperByte ) << 8) | ( uint16) LowerByte;

 

i.e. cast to uint16 first, then shift, vs shift 8 bits out of uint8, then cast ?

 

Regards, Dana.



Re: using the usart component

Bob Marlowe posted on 22 Jan 2013 12:58 PM PST
Top Contributor
1768 Forum Posts

Yes, Dana- You're right. Not good to write at late hours C programs life.

 

Bob



Re: using the usart component

Bob Marlowe posted on 22 Jan 2013 01:03 PM PST
Top Contributor
1768 Forum Posts

Just checked the precedence, could have written

 

USARTWord = (uint16)UpperByte << 8 | (uint16)LowerByte;

 

Bob






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20