The question about the connecting the FlexCan block from NXP with CAN Pack in simulink

cancel
Showing results for 
Search instead for 
Did you mean: 

The question about the connecting the FlexCan block from NXP with CAN Pack in simulink

Jump to solution
1,939 Views
edenli
Contributor V

Hi Guys,

I have a doubt about the FlexCan simulink block from NXP,i wanna use the CAN PACK block with the FlexCAN block ,like as the Can block from TI,shown as below:

pastedImage_1.png

becasue the CAN Pack can load the DBC file shown above, we can give the value to the signal,then the eCan Trans block will send the signals out.

but the FlexCan block from NXP seems not connect the CAN PACK block in the simulink,because the dimensional is inconformity.

pastedImage_2.png

i have another question how can i send a 12 bit signal using the can block from NXP?

Tags (1)
1 Solution
1,163 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi edenli‌,

I do not have the Vehicle Network Toolbox license - but from the Matlab Help, the CAN PACK is going to output a full CAN frame message.

The NXP CAN block expects only the DATA payload (B7 - B0) (source)

pastedImage_1.png

Therefore, you need to de-serialized the message you get from the CAN PACK and extract DATA payload. Then since you need to transmit only 12bits you should keep only B0 and B1, pass it to the CAN Transmit and set up its length input to value 2 instead of 8.

That should to the trick.

Hope this helps!

Daniel

View solution in original post

8 Replies
1,163 Views
dumitru-daniel_
NXP Employee
NXP Employee

Have you fixed the problem ?

0 Kudos
1,163 Views
ruicui
Contributor II

Hello Daniel,

No, I haven't. I need to load the dbc first. The output of "CAN Pack" is "CAN message" type. I am not sure how to convert/extract data payload to uint8 type.  

I think its possible to import .c/.h which generated by Vector Geny tool, then call the signal function directly from Matlab.

Thanks,

Rui

0 Kudos
1,163 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi Rui, 

An example of PACK can be found here: How to Build and Configure a CAN with S32K to Emulate Automotive Body Control Infrastructure  in the slave.mld model. (unpack example can be found in master.mdl)

pastedImage_1.png

I think its possible to import .c/.h which generated by Vector Geny tool, then call the signal function directly from Matlab.

Yes, there are multiples ways. Please check:

Tip #3: MBD Toolbox - Add custom code to your Simulink model

Tip #5: MBD Toolbox - Use S-Function to call your custom code anywhere in the model

or use Simulink Custom Code blocks

pastedImage_6.png

Hope this helps!

Daniel

0 Kudos
1,164 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi edenli‌,

I do not have the Vehicle Network Toolbox license - but from the Matlab Help, the CAN PACK is going to output a full CAN frame message.

The NXP CAN block expects only the DATA payload (B7 - B0) (source)

pastedImage_1.png

Therefore, you need to de-serialized the message you get from the CAN PACK and extract DATA payload. Then since you need to transmit only 12bits you should keep only B0 and B1, pass it to the CAN Transmit and set up its length input to value 2 instead of 8.

That should to the trick.

Hope this helps!

Daniel

1,163 Views
edenli
Contributor V

Hi Daniel,

Thank you for your help, Now i have achieved it!

Best Regards!

Eden Li

0 Kudos
1,163 Views
ruicui
Contributor II

Hello guys, 

How do you de-serialized the message? Simulink doesn't allow me to convert the "CAN message" type. So I can't go to next step and extract data payload from it.

Thanks,

Rui

0 Kudos
1,163 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi Rui Cui, 

In case you have the Embedded Coder toolbox you could use the CAN Pack/Unpack blocks. 

pastedImage_1.png

An example how to use it can be found here: https://community.nxp.com/thread/465130 

Hope this helps!

Daniel

0 Kudos
1,163 Views
ruicui
Contributor II

Hello Daniel,

Apparently, I didn't explain my question well. My question is similar as Eden Li: I want to load certain dbc first and then use S32K library/blocks to send my CAN message.

However, see following screenshot:

pastedImage_1.png

"FCAN_Send" need 8 bytes data. But by using "CAN Pack", the output data type is "CAN message", Matlab doesn't allow me to convert to any type. So I can't extract the data payload and convert to uint8. 

Thanks,

Rui Cui

0 Kudos