S32K144 FlexCAN Receive messages

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

S32K144 FlexCAN Receive messages

1,737 Views
w_lingjun
Contributor III

Hi,

I have some problems about FlexCAN receive message when I develop on S32K144.

I have to receive more than 10 messages from CANbus to get useful signals from them in my current project. So I need config message box for every message as following code, right? 

#define RX_CAN1FRAME_NUMBER     10
uint32_t MsgId[10] = {0x1f5, 0xf9, 0x22a, 0x541, 0x540, 0xf1, 0x1f1, 0x169, 0x1f2, 0x46a};
...
for(Index=0; Index<RX_CAN1FRAME_NUMBER; Index++)
{
   FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, Index,  &data_std_info, MsgId[Index]);
 }

And I have to call receive function in a loop to receive every message as following code, right?
...
for(index=0; index<RX_CAN1FRAME_NUMBER; index++)
 {
    FLEXCAN_DRV_Receive(INST_CANCOM1, index, &RxMsg);
}

And it is not necessory to use following function when initialize, right?
  INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
  INT_SYS_SetPriority(CAN0_ORed_0_15_MB_IRQn,0U);

Waiting for your reply, thank you~

Best regards,
Sarah

0 Kudos
9 Replies

1,468 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, if you cannot create ID ranges, due to so different IDs to receive, it is good to prepare RX MB for each ID. Or you can try to use RXFIFO if CAN FD is not used.
FLEXCAN_DRV_ConfigRxMb must be called for each MB and each time you want to receive a message to it. It initializes some internal variables and enable interrupt fro given MB.
It is not needed to initialize interrupt, it is done by driver itself.

BR, Petr 

0 Kudos

1,468 Views
w_lingjun
Contributor III

Hi Petr,

Thank you for your reply!

As you suggested, I can use RXFIFO. If I use RXFIFO, I just call function FLEXCAN_DRV_RxFifo(); only one time, right?

Best regards,

Sarah

0 Kudos

1,468 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

no, in case of RXFIFO you still need to call FLEXCAN_DRV_RxFifo() again after you read a message.

BR, Petr

0 Kudos

1,468 Views
w_lingjun
Contributor III

Hi Petr,

Thank you very much, Now I can receive messages using RXFIFO.

And when I test, I find a problem description as below.

I use CAN0 and CAN1 in current project based on S32K142, and use RXFIFO.

CAN0 defined receiving messages, id is {0x1f5, 0xf9, 0x22a, 0x541, 0x540, 0xf1, 0x1f1, 0x169, 0x1f2, 0x46a, 0xc9, 0x1df, 0x702, 0x7df, 0x771};

CAN0 defined receiving messages, id is {0x353, 0x22a, 0x146, 0x163};

And I install event callback for these two CANs.

The problem is when I receive 0x1f5, it should call CAN0 callback, but it calls both two callback. I think this is a wrong action.

If I receive 0x353, just CAN1 callback called, I think this is the correct action.

Could you please help me explain this problem?

Waiting for you reply!

Best regards,

Sarah

0 Kudos

1,468 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if you will share the project, it can be checked, otherwise have no explanation.

Maybe one, you should initialize full ID filter table, based on RFFN setting.

BR, Petr  

0 Kudos

1,468 Views
w_lingjun
Contributor III

Hi Petr,

The attachment is a simple project, just for CAN RX and TX.

Please help me check why CAN1 can receive the message which id is included in CAN0.

CAN1 use the transceiver TJA1041T, you can ignore the operation for it, just use your own transceiver.

    PINS_DRV_SetPins(PTC, 1 << UJA_EN);  //operation for TJA1041T
    PINS_DRV_SetPins(PTA, 1 << UJA_STB); //operation for TJA1041T

Thank you very much!

Best regards,

Sarah

0 Kudos

1,468 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

as I wrote last time, you should define full ID filter table. You set 8 elements in CAN1 component, but in the code define just 4 IDs. You can try to debug a code and see how the ID filter table is actually filled within MBs area.

So the changes could be following

flexcan_id_table_t Can2RxFilter[8];
uint32_t Can2IDList[8] = {0x353, 0x22a, 0x146, 0x163,0,0,0,0};

for(index=0; index<8; index++)
{
Can2RxFilter[index].isRemoteFrame = false;
Can2RxFilter[index].isExtendedFrame = false;
Can2RxFilter[index].id = Can2IDList[index];
}

BR, Petr

0 Kudos

1,468 Views
w_lingjun
Contributor III

Hi Petr,

Thank you for your support.

Even if I define full ID filter table, the problem still exsit.

I try to modify the second parameter "id_format" from FLEXCAN_RX_FIFO_ID_FORMAT_C to  FLEXCAN_RX_FIFO_ID_FORMAT_A in following function, the problem is resolved. 

void FLEXCAN_DRV_ConfigRxFifo(
    uint8_t instance,
    flexcan_rx_fifo_id_element_format_t id_format,
    const flexcan_id_table_t *id_filter_table);

Is that means format A is more exactly than format C when filte received frames?

Best  regards,

Sarah

0 Kudos

1,468 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

format of the filter elements are explained in the chapter 53.4.6 Rx FIFO structure of the RM.

BR, Petr

0 Kudos