CAN packing
At the moment I am having to manually pack CAN messages using bit shifts, masks, mux etc in order to construct 8 bytes of data to transmit a CAN message. An example of one such message is shown below...
However, this is very tedious especially when there are lots of CAN messages to pack.
I came across the embedded coder block 'CAN pack' which imports the CAN database, but unfortunately I cannot get this to work.
There is a data type mismatch because the 'CAN Pack' output is not a structure...
The 'CAN pack' block does not seem to output structures...
Should this 'CAN pack' block work with the 'FCAN_Send' block and if so, how ?
If not, is there another way of packing the CAN messages (preferably by importing a CAN database) ?
CAN unpacking
I haven't tried unpacking signals from the 'FCAN_Receive' block yet, so far I have only unpacked the 8 raw bytes of data as shown below...
For testing purposes I have made byte 1 control a digital output (LED).
How can I extract the signals from the 8 bytes of raw data, without having to manually implement the unpacking using bit shifts, masks, mux etc
I tried the embedded coder block 'CAN unpack' which imports the CAN database, but unfortunately I cannot get this to work.
There is a data type mismatch because the 'CAN unpack' input does not allow structures...
Should this 'CAN unpack' block work with the 'FCAN_Receive' block and if so, how ?
If not, is there another way of unpacking the CAN messages (preferably by importing a CAN database) ?
Solved! Go to Solution.
UPDATE:
I have managed to get 'CAN Unpack' to work as follows:
1. Create the datatype 'CAN_MESSAGE_BUS' by running the command 'canMessageBusType' at the MATLAB prompt. To see the structure of the datatype, run 'CAN_MESSAGE_BUS.Elements'...
2. Create a bus and set the output data type to 'CAN_MESSAGE_BUS'. The inputs to the bus are as follows:
3. The following outputs from the NXP Rx Complete block are used as the inputs to the 'CAN Unpack' block...
Simply awesome John to document your work for the benifit of the community . I am also stuck on this issue , well check on your suggested solution.
UPDATE:
I have managed to get 'CAN Unpack' to work as follows:
1. Create the datatype 'CAN_MESSAGE_BUS' by running the command 'canMessageBusType' at the MATLAB prompt. To see the structure of the datatype, run 'CAN_MESSAGE_BUS.Elements'...
2. Create a bus and set the output data type to 'CAN_MESSAGE_BUS'. The inputs to the bus are as follows:
3. The following outputs from the NXP Rx Complete block are used as the inputs to the 'CAN Unpack' block...
UPDATE:
I have managed to get 'CAN Pack' to work, but I'm not having any luck with 'CAN Unpack'.
To get 'CAN Pack' to work, I set the output as a bus...
The bus elements are shown below...
In this case I selected the bus elements Data, Length and ID to use with the FCAN_Send block.
I tried creating the same bus for 'CAN Unpack', but this did not work...