cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

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
Reply
3 Replies
Honored Contributor II

Combining two 8-bit variables into 16 bit:

   
uint8_t low=42; uint8_t high=42; uint16_t word=low+high>>8;
0 Likes
Reply
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
Reply
Honored Contributor II

In C: yes.

0 Likes
Reply