- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
awesome, thanks 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.. 😆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
well, something like
USARTWord = (uint16)(UpperByte << 😎 | (uint16)LowerByte;
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, Dana- You're right. Not good to write at late hours C programs life.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just checked the precedence, could have written
USARTWord = (uint16)UpperByte << 8 | (uint16)LowerByte;
Bob