Hi @JQiggle ,
We are sorry for not explaining clearly the difference between Blocking and Non-blocking modes in our help. We'll update that part in the next release.
As you found out already, the blocking CAN Rx and Tx operations will wait for the specified timeout duration to receive or send a CAN message. But the timeout value is not hardcoded, it is configurable from the CAN Receive or Send block. In the case of non-blocking mode, it will not wait for the operation to complete. Instead, an Rx or Tx interrupt is triggered on the completion, which is handled through the CAN ISR block.
In the case of Rx the blocking mode maybe is not so useful, but for Tx it can help you reuse the same message buffer and simplify your model because you don't need to add any extra blocks.
Can you try to apply the following patch:
1. Download and unzip the attached fcan_mpc_isr.zip archive.
2. Run in Matlab winopen(fullfile(mbd_find_mpc_root, 'mbdtbx_mpc', 'blocks', 'fcan'))
3. Copy fcan_mpc_isr.tlc file in the newly opened explorer win.
4. Build your model.
There are multiple approaches for what you want to accomplish:
1. If the number of used IDs does not exceed the maximum number of message buffers, you can call CAN Receive for each message ID, each call using a different message buffer (MB).
2. If you want to reuse message buffers, you will need to specify an ID mask that accepts multiple IDs.
The IDs and ID masks are used to filter incoming IDs. There is bit-to-bit correspondence between received ID, mask, and programmed MB ID (the one configured in the CAN Receive or Send block). The mask says if the corresponding incoming ID bit is compared with the programmed ID bit.
If the mask bit is cleared or 0 the incoming ID bit is not compared, it is don’t care. If the mask bit is set or 1, then there must be an exact match between the incoming ID bit and the programmed ID bit. To receive a message into a MB/RXFIFO all relevant bits with mask bit set must be equal to programmed one.
For example:
1. You have ID 0x3FE, ID mask 0xFFFFFFFF, message buffer (MB) 1.
Because the ID mask has all bits set to 1, which means that all bits from ID will be compared and there should be an exact match between the programmed ID, 0x3FE, and the incoming ID, in MB 1 will be received messages with ID 0x3FE only.
2. You want to receive the following IDs, 0x3FE and 0x3FF in message buffer (MB) 2.
0x3FE is in binary 0b1111111110
0x3FF is in binary 0b1111111111
Looking at the binary representation only the 1st bit changes, which means that the 1st bit of the ID mask should be 0 or don't care to allow 0 or 1 as values. All the other bits will be set to 1. So the ID mask will be 0b11111111111111111111111111111110 or 0xFFFFFFFE.
The CAN ISR block returns the ID and Data of the received message. Inside the subsystem that is triggered by the CAN ISR block, you can use a SwitchCase block that will take the ID as input to execute different Switch Case Action subsystem based on the received ID. An example of this implementation can be found in flexcan_echo_mpc574x.mdl example from our toolbox.
Regards,
Paul