■ PHOTO 2. The Microchip CAN bus
analyzer tool is akin to an Ethernet
Sniffer. Everything that is thrown
onto the CAN bus is captured for your
reading entertainment.
the pointed-to structure which is, in
this case, CANRxMessageBuffer:
if(message->data[0] == 0x41)
{
//Data is an ‘A” -
//Do something
}
CANRxMessageBuffer message;
Once we’ve done our thing with
the data payload, we need to
update the receive message buffer’s
internal pointers and enable the
receive interrupt trigger:
The CAN receive interrupt handler we just examined
determined that a valid message had been posted and set
the flag isCAN2MsgReceived to TRUE. So, we can clear
the isCAN2MsgReceived flag and obtain the address of
the newly received CAN message:
CANUpdateChannel(CAN2, CAN_CHANNEL1);
CANEnableChannelEvent(CAN2, CAN_CHANNEL1,
CAN_RX_CHANNEL_NOT_EMPTY, TRUE);
We’re ready to receive the next CAN message.
if(isCAN2MsgReceived == FALSE)
{
CAN TO CAN
return;
}
isCAN2MsgReceived = FALSE;
message = CANGetRxMessage(CAN2,CAN_CHANNEL1);
Now that we have access to the receive message
buffer that contains the incoming data payload, we can
assess the data payload using a pointer to the members of
If you clone the CAN2 routines to CAN1 routines,
you only need one chipKIT network shield to run the CAN
transmit/receive code we’ve just discussed. I opted to use
a pair of chipKIT Max32s. Each chipKIT Max32 was
loaded with a chipKIT network shield. Using two CAN
74
November 2011