can not receive the CAN frame with extended ID

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

can not receive the CAN frame with extended ID

跳至解决方案
1,413 次查看
fedora
Contributor III

Hi team:

     I use the can_pal0 and can_pan2 module in PE , and they can send and receive data with standard ID each other.  Then I change the CAN_MSG_ID_STD to CAN_MSG_ID_EXT,  and CAN ID from 0x01 to 0x10001,  but CAN0 cannot receive data sent by CAN2.

     Here are the codes for CANx initial and send, please help me check them.

 
void CAN0_Init(void)
{
  CAN_Init(&can_pal0_instance, &can_pal0_Config0);
  can_buff_config_t Rx_buffCfg =  {
      .enableFD = false,    
      .enableBRS = false,   
      .fdPadding = 0U,
      .idType = CAN_MSG_ID_EXT,//CAN_MSG_ID_STD,
      .isRemote = false
  };
 
  can_buff_config_t Tx_buffCfg =  {
      .enableFD = false,                
      .enableBRS = false,               
      .fdPadding = 0U,
      .idType = CAN_MSG_ID_EXT,//CAN_MSG_ID_STD,
      .isRemote = false
  };
  CAN_ConfigRxBuff(&can_pal0_instance, RX_MAILBOX_CAN0, &Rx_buffCfg, Rx_Filter);
  CAN_ConfigTxBuff(&can_pal0_instance, TX_MAILBOX_CAN0, &Tx_buffCfg);
  CAN_SetRxFilter(&can_pal0_instance,CAN_MSG_ID_EXT/*CAN_MSG_ID_STD*/,RX_MAILBOX_CAN0,0);
  CAN_InstallEventCallback(&can_pal0_instance,&CAN0_Callback_Func,(void*)0);
  CAN_Receive(&can_pal0_instance, RX_MAILBOX_CAN0, &recvMsg_CAN0);
}
 
void CAN2_Init(void)
{
  CAN_Init(&can_pal2_instance, &can_pal2_Config0);
  can_buff_config_t Rx_buffCfg =  {
      .enableFD = false,
      .enableBRS = false,
      .fdPadding = 0U,
      .idType = CAN_MSG_ID_EXT,//CAN_MSG_ID_STD,
      .isRemote = false
  };
 
  can_buff_config_t Tx_buffCfg =  {
      .enableFD = false,
      .enableBRS = false,
      .fdPadding = 0U,
      .idType = CAN_MSG_ID_EXT,//CAN_MSG_ID_STD,
      .isRemote = false
  };
  CAN_ConfigRxBuff(&can_pal2_instance, RX_MAILBOX_CAN2, &Rx_buffCfg, Rx_Filter);
  CAN_ConfigTxBuff(&can_pal2_instance, TX_MAILBOX_CAN2, &Tx_buffCfg);
  CAN_SetRxFilter(&can_pal2_instance,CAN_MSG_ID_EXT/*CAN_MSG_ID_STD*/,RX_MAILBOX_CAN2,0);
  CAN_InstallEventCallback(&can_pal2_instance,&CAN2_Callback_Func,(void*)0);
  CAN_Receive(&can_pal2_instance, RX_MAILBOX_CAN2, &recvMsg_CAN2);
}
 
CAN2 send to CAN0:
can_message_t Tx_msg = {
.cs = 0U,
.id = 0x10001,    //extended ID,  more than 11 bit
.data[0] = 0xaa,
.data[1] = 0xaa,
.data[2] = 0xaa,
.data[3] = 0xaa,
.data[4] = 0xaa,
.data[5] = 0xaa,
.data[6] = 0xaa,
.data[7] = 0xaa,
.length = 8
};
CAN_Send(&can_pal2_instance, TX_MAILBOX_CAN2, &Tx_msg);
 
Thanks!
 
fedora
标签 (1)
0 项奖励
回复
1 解答
1,347 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@fedora

There is no problem with receiving. The error is that you are not sending an extended frame.

place "CAN_ConfigTxBuff()" before "CAN_Send()"

"

{
can_message_t Tx_msg = {
.cs = 0U,
.id = 0x10001,
.data[0] = 0x20,
.data[1] = 0x21,
.data[2] = 0x22,
.data[3] = 0x23,
.data[4] = 0x24,
.data[5] = 0x25,
.data[6] = 0x26,
.data[7] = 0x27,
.length = 8
};
can_buff_config_t Tx_buffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_EXT,//CAN_MSG_ID_STD
.isRemote = false
};
CAN_ConfigTxBuff(&can_pal2_instance, TX_MAILBOX_CAN2, &Tx_buffCfg);
CAN_Send(&can_pal2_instance, TX_MAILBOX_CAN2, &Tx_msg);
u1_printf("CAN2 send: 20 21 22 23 24 25 26 27\r\n");

"

在原帖中查看解决方案

0 项奖励
回复
6 回复数
1,387 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@fedora

Could you please share the project so that i can test it for you.

0 项奖励
回复
1,379 次查看
fedora
Contributor III

Thanks for your help!

Please find attached that s32k144 CAN testing project.

If the CAN_MSG_ID_STD macro is used, the CAN0, CAN1 and CAN2 can communicate with each other, but replace CAN_MSG_ID_STD with CAN_MSG_ID_EXT cannot receive any data.

Thanks again!

 

Fedora

0 项奖励
回复
1,366 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@fedora

I test flexcan0 with pcan and i can see no problem on myside.

Senlent_0-1749453463329.png

 

But I do find some issues with your flexcan settings.

The sampling point for flexcan0 is 75%, but the sampling points for flexcan1 and flexcan2 are

87.5%, which may cause communication failure.

 

It is recommended that you first use a PC tool such as PCAN to ensure that each

FLEXCAN instance is working properly.

0 项奖励
回复
1,359 次查看
fedora
Contributor III

Thanks, Senlent.

In my project, I hope CAN2 can send the following data that  ID is 0x10001,  so it's an extended frame;  

Expected to the CAN0 can get ID 0x10001 as well , but the ID received by CAN0 is 0x01,  why?

can_message_t Tx_msg = {
.cs = 0U,
.id = 0x10001,
.data[0] = 0x20,
.data[1] = 0x21,
.data[2] = 0x22,
.data[3] = 0x23,
.data[4] = 0x24,
.data[5] = 0x25,
.data[6] = 0x26,
.data[7] = 0x27,
.length = 8
};

fedora_0-1749465290024.png 

extended frame format

 

0 项奖励
回复
1,348 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@fedora

There is no problem with receiving. The error is that you are not sending an extended frame.

place "CAN_ConfigTxBuff()" before "CAN_Send()"

"

{
can_message_t Tx_msg = {
.cs = 0U,
.id = 0x10001,
.data[0] = 0x20,
.data[1] = 0x21,
.data[2] = 0x22,
.data[3] = 0x23,
.data[4] = 0x24,
.data[5] = 0x25,
.data[6] = 0x26,
.data[7] = 0x27,
.length = 8
};
can_buff_config_t Tx_buffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_EXT,//CAN_MSG_ID_STD
.isRemote = false
};
CAN_ConfigTxBuff(&can_pal2_instance, TX_MAILBOX_CAN2, &Tx_buffCfg);
CAN_Send(&can_pal2_instance, TX_MAILBOX_CAN2, &Tx_msg);
u1_printf("CAN2 send: 20 21 22 23 24 25 26 27\r\n");

"

0 项奖励
回复
1,330 次查看
fedora
Contributor III

Thanks, Senlent!

After testing, your method is correct.

Before calling Can_send, Tx buffer needs to be reinitialized.

 

0 项奖励
回复