CAN RX Not Triggering

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN RX Not Triggering

949 Views
schourasiya
Contributor II

I'm using S32K344 with MATLAB MBDT. I’ve set up CAN RX and TX using Can_MainFunction_Read/Write, IRQ handler, and CanIf_RxIndication schourasiya_0-1753095450635.png

schourasiya_1-1753095464924.png

I do not currently have debugging set up—only flashing is available. So, to confirm RX, I'm transmitting back the received data. However, RX is never triggered—no IRQ hits or loopback response observed on the bench.

Can you confirm:

  1. Required .mex settings for RX HRH in polling mode other than the following?

    schourasiya_3-1753095800703.png
  2. Any specific interrupt or object mappings needed for RX IRQ to trigger in MBDT?

0 Kudos
Reply
5 Replies

916 Views
SorinIBancila
NXP Employee
NXP Employee

Hello,

First of all, can you share with me what MATLAB version do you use and what version of the toolbox did you install?

In the Model Based Design Toolbox for S32K3, there are two example that might help you develop your application:

s32k3xx_can_receive_s32ct: Shows how to receive CAN messages with interrupts. When a message is received, an onboard LED is toggled.

s32k342_can_transmit_s32ct: Shows how to send CAN messages and increments a counter every time a message is successfully send.

The later example is configured for a S32K342 board, but you can take a look at the example to see the workflow. Further details about these examples can be found inside the help file (html files), located next to the model.

 

Regarding your screenshots:

  • You don't need to use the CAN_MainFunction_Read and CAN_MainFunction_Write block if you want to use IRQ handlers. These two blocks are for polling receive/transmit. 

An example implementation can look like below. If a CAN message with ID = 10 (decimal) is received, a CAN message with ID = 255 (decimal) is sent back to the CAN bus. Data is echoed.

SorinIBancila_0-1753098764177.png

  • Another important aspect is that you need to make sure the Can Hw Filter Code and Can Hw Filter Mask are properly set for each CanHardwareObject. A message is received if the following rule is true (bitwise operations), otherwise the CAN message is discarded.

RECEIVED_ID & FILTER_MASK = FILTER_CODE & FILTER_MASK

SorinIBancila_1-1753099060223.png

 

Best regards,

Sorin Bancila

0 Kudos
Reply

873 Views
schourasiya
Contributor II

I’m using MATLAB 2023a with MBDT v1.5. I’ve already reviewed the provided examples, but without a debugger, I’m unable to verify if CAN RX or the ISR is actually working, and the examples haven’t helped much in this case.

I tried the RX→TX loopback setup shown in your screenshots, but the TX isn't triggering back either. Could you help with possible reasons?

Also, since Simulink doesn’t expose any CanHardwareObject selection, how does the ISR determine which HRH to use internally?

Lastly, how should the Can Hw Filter Code be configured to allow receiving a wide or generic range of extended IDs — for example, all PGNs starting with 0x18, or to receive all messages?

0 Kudos
Reply

738 Views
schourasiya
Contributor II

Here attached is the .mex file I am using for CAN reception. Can you help find out the reason why CANIf_RXIndication is not triggering at any instance (neither standard nor extended RX)?

0 Kudos
Reply

727 Views
SorinIBancila
NXP Employee
NXP Employee

Hello,

1. One way to verify if the ISR is triggered without a debugger is to increment a variable inside the triggered subsystem and visualize it in the FreeMASTER.

2. To test the CAN using the loopback you need to do the following:

  •  Enable the LoopBack Mode from the CAN_43_FLEXCAN -> CanController.

SorinIBancila_1-1753792337726.png

  • Make sure to initialize the CAN component and set the mode to "CAN_CS_STARTED" and enable the interrupts. The blocks below can be put in a "Initialize Function" subsystem to execute them only once.

SorinIBancila_5-1753792886292.png

 

  • Use the Can_Write to send a CAN Message. Make sure to open the block and select the type of the message (Extended/Standard, CAN FD Message)

 

SorinIBancila_4-1753792661666.png

  • For each CanHardwareObject I recommended to explicitly select STANDARD or EXTENDED. I would not recommended in this stage to use a single HardwareObject set on MIXED.

3. The ISR block doesn't allow to select which CanHardwareObject to use when triggering an interrupt. All the CanHardwareObject trigger the same interrupt and you need to implement in Simulink the logic to sort them by the HardwareObject ID.

4. To receive all messages, The Can Hw Filter Code and Can Hw Filter mask must be set to 0. If you want to accept only a range of IDs, please check the original reply. Below you have a few examples with the MASK set to 3 and FILTER_CODE to 1. For case 1, 3, 4 the message is received, whereas for the case 2, the message ID isn't received. All the numbers below are represented in binary form to better illustrate the workflow.

SorinIBancila_6-1753793186429.png

 

 

Best regards,

Sorin Bancila

 

 

0 Kudos
Reply

626 Views
schourasiya
Contributor II
Hi, thanks it is working.