The first CAN message received after MCU power-up is always empty.

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

The first CAN message received after MCU power-up is always empty.

312 Views
Hanz
Contributor I

Hi Expert,

The first CAN message received after MCU power-up is always empty.

Below it the CAN init and it's call back function.

void CAN0_init() {
  IntCtrl_Ip_EnableIrq(FlexCAN0_0_IRQn);
  IntCtrl_Ip_EnableIrq(FlexCAN0_1_IRQn);
  IntCtrl_Ip_EnableIrq(FlexCAN0_2_IRQn);
  IntCtrl_Ip_InstallHandler(FlexCAN0_0_IRQn,&CAN0_ORED_IRQHandler,NULL_PTR);
  IntCtrl_Ip_InstallHandler(FlexCAN0_1_IRQn,&CAN0_ORED_0_31_MB_IRQHandler,NULL_PTR);
  IntCtrl_Ip_InstallHandler(FlexCAN0_2_IRQn,&CAN0_ORED_32_63_MB_IRQHandler,NULL_PTR);

  FlexCAN_Ip_Init(CAN_DEV_INSTANCE, &FlexCAN_State0, &FlexCAN_Config0);
  FlexCAN_Ip_SetRxMaskType(CAN_DEV_INSTANCE,FLEXCAN_RX_MASK_INDIVIDUAL);
  FlexCAN_Ip_SetRxIndividualMask(CAN_DEV_INSTANCE,RX_MB_IDX,0);
  FlexCAN_Ip_SetStartMode(CAN_DEV_INSTANCE);
  FlexCAN_Ip_ConfigRxMb(CAN_DEV_INSTANCE, RX_MB_IDX, &rx_info, MSG_ID);
  FlexCAN_Ip_Receive(CAN_DEV_INSTANCE, RX_MB_IDX, &rxData, FALSE);  //clear redundancy data

  /* Start Receive CAN Data */
( void ) FlexCAN_Ip_RxFifo(CAN_DEV_INSTANCE, &Can0Rx_isr);
( void ) FlexCAN_Ip_SetErrorInt(CAN_DEV_INSTANCE, FLEXCAN_IP_INT_BUSOFF, TRUE);
 
}

 

void flexcan0_Callback(uint8 instance, Flexcan_Ip_EventType eventType, uint32 buffIdx,
  const Flexcan_Ip_StateType *flexcanState)
{
 
switch(eventType)
{
case FLEXCAN_EVENT_RX_COMPLETE:
 
FlexCAN_Ip_Receive(CAN_DEV_INSTANCE, RX_MB_IDX, &Can0Rx_isr, FALSE);
  break; 
}

 

RTD version:

/*==================================================================================================
*   Project              : RTD AUTOSAR 4.7
*   Platform             : CORTEXM
*   Peripheral           : FLEXCAN
*   Dependencies         :
*
*   Autosar Version      : 4.7.0
*   Autosar Revision     : ASR_REL_4_7_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 5.0.0
*   Build Version        : S32K3_RTD_5_0_0_D2408_ASR_REL_4_7_REV_0000_20241002
*
*   Copyright 2020 - 2024 NXP
================================
Tags (1)
0 Kudos
Reply
3 Replies

285 Views
Hanz
Contributor I

Hi Petr,

 

I can't share the simple project with you, but here is the FlexCAN configuration.

Hanz_0-1746493762731.png

The test environment is as follows: the MCU's CAN_H is connected to the PCAN's CAN_H, and CAN_L is connected to CAN_L.

A CAN message is sent via PCAN Viewer right after the MCU powers up. Then we check whether the message is received.

 

Could this be an RX FIFO configuration issue?

 

Thanks.

 

0 Kudos
Reply

279 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

a FlexCAN config does not show RXFIFO is enabled so why FlexCAN_Ip_RxFifo is called then?
For the first message do you see callback is called and rxbuffer is empty/wrong or callback is not called at all?
Did you do any measurement to be sure all init is done before message came? Do you see any kind of error detected?

BR, Petr

0 Kudos
Reply

290 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I am not aware of situation which can lead to behavior you wrote.
Are you able to share full simplified project for testing and specify the bus condition and behavior for the issue (message send from other node, rxbuffer content after receiving, etc)?
Your code includes RXFIFO_receive calling. How the RXFIFO is used/configured?

BR, Petr

0 Kudos
Reply