4200L Best way to extract uint16 from CAN Message?

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

cross mob
Anonymous
Not applicable

Hi,

   

I'm searching for an easy way to extract/put uint16 form/in CAN Messages/Mailboxes

   

Before (with other Platform) I do this:

   

                UB12=(*(short *) &CAN_Receive_Data[1]);
                UB24=(*(short *) &CAN_Receive_Data[3]);

   

        (*(short *) &CAN_Send_Data[1])=UB12;
        (*(short *) &CAN_Send_Data[3])=UB24;

   

Regards,

   

Michael

0 Likes
3 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Combining two 8-bit variables into 16 bit:

   
uint8_t low=42; uint8_t high=42; uint16_t word=low+high>>8;
0 Likes
Anonymous
Not applicable

That's not the Problem. I want extract from CAN_Message_Mailbox:

   

    UB12 = ((uint16) ((uint16) CAN0_RX_DATA_BYTE2(CAN0_RX_MAILBOX_0) << 8u)) | CAN0_RX_DATA_BYTE1(CAN0_RX_MAILBOX_0);
    UB24 = ((uint16) ((uint16) CAN0_RX_DATA_BYTE4(CAN0_RX_MAILBOX_0) << 8u)) | CAN0_RX_DATA_BYTE3(CAN0_RX_MAILBOX_0); 

   

worked, but is it the easiest way?

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

In C: yes.

0 Likes