using the usart component

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

cross mob
Anonymous
Not applicable

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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

View solution in original post

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

awesome, thanks 🙂 

0 Likes
Anonymous
Not applicable

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.. 😆 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

well, something like

   

 

   

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

   

 

   

Happy coding

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Bob, should this -

   

 

   

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

   

 

   

be this -

   

 

   

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

   

 

   

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

   

 

   

Regards, Dana.

Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

 

   

Bob

Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Just checked the precedence, could have written

   

 

   

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

   

 

   

Bob

0 Likes