CAN msg buffer mask

Status
Not open for further replies.

Fox95

Active member
question: is there a way to mask off a hex value?

example of hex value i am transmitting over CAN:

msg.buf[0] = 0x0315;
----------------------------------------
lets say i only want to transmit the "03" in that line of code above is there a easy way to mask off the "15"

and vice versa, lets say i just want to transmit the "15" is there a way to mask off the "03" ?
 
question: is there a way to mask off a hex value?

example of hex value i am transmitting over CAN:

msg.buf[0] = 0x0315;
----------------------------------------
lets say i only want to transmit the "03" in that line of code above is there a easy way to mask off the "15"

and vice versa, lets say i just want to transmit the "15" is there a way to mask off the "03" ?

i figured out the answer to my question, so i post it in case someone else searches this in the future.

msg.buf[0] = 0x0315 >> 8; is the answer if you want to only transmit the 03 portion.

if shifts 8 bits. (i think) but it works properly, and you dont need to mask of the 03 if you wanted to only transmit 15, becuase it will transmit 15 regardless of the values before it defaults to the position of the 15.

so if you want to transmit this hex value (0x0315) over CAN

msg.buf[0] = 0x0315 >> 8;
msg.buf[1] = 0x0315;
msg.buf[2] = 0x00;
msg.buf[3] = 0x00;
msg.buf[4] = 0x00;
msg.buf[5] = 0x00;
msg.buf[6] = 0x00;
msg.buf[7] = 0x00;

would work.

the CAN data stream will show: 03 15 00 00 00 00 00 00
 
Status
Not open for further replies.
Back
Top