I encounter a problem in debugging CANFD of 5748G. I transmit CANFD message by MCU , receive CAN FD message by Canalyer. The trace window is showed as followes
The ID and the data is right, why there is a stuff err? please help me, thank you!
My code is as followes:
void initCAN_0(void) { /* General init. No MB IDs iniialized */
uint8_t i;
CAN_0.MCR.B.MDIS = 1; /* Disable module before selecting clock source*/
CAN_0.CTRL1.B.CLKSRC=0; /* Clock Source = oscillator clock (40 MHz) */
CAN_0.MCR.B.MDIS = 0; /* Enable module for config. (Sets FRZ, HALT)*/
CAN_0.MCR.B.FRZ =1; // enable module to enter freezing mode.
CAN_0.MCR.B.HALT = 1;
while (!CAN_0.MCR.B.FRZACK) {}/* Wait for freeze acknowledge to set */
while (!CAN_0.MCR.B.NOTRDY) {}/* Wait for freeze acknowledge to set */
CAN_0.MCR.B.RFEN = 0;
CAN_0.MCR.B.WAKMSK = 0;
CAN_0.MCR.B.SOFTRST = 0;
CAN_0.MCR.B.SUPV = 0;
CAN_0.MCR.B.SLFWAK = 0;
CAN_0.MCR.B.WRNEN = 0;
CAN_0.MCR.B.WAKSRC = 0;
CAN_0.MCR.B.SRXDIS = 1;
CAN_0.MCR.B.IRMQ = 1;
CAN_0.MCR.B.DMA = 0;
CAN_0.MCR.B.PNET_EN = 0;
CAN_0.MCR.B.LPRIOEN = 0;
CAN_0.MCR.B.AEN = 1;
CAN_0.MCR.B.FDEN = 1;
CAN_0.MCR.B.IDAM = 0;
CAN_0.MCR.B.MAXMB = 0X3F;
CAN_0.CTRL1.R = 0x04DB0086;
CAN_0.CTRL1.B.BOFFMSK = 0;
CAN_0.CTRL1.B.ERRMSK = 0;
CAN_0.CTRL1.B.LPB = 0;
CAN_0.CTRL1.B.TWRNMSK = 0;
CAN_0.CTRL1.B.RWRNMSK = 0;
CAN_0.CTRL1.B.BOFFREC = 0;
CAN_0.CTRL1.B.TSYN = 0;
CAN_0.CTRL1.B.LBUF = 0;
CAN_0.CTRL1.B.LOM = 0;
//canFD格式增加如下配置
CAN_0.CTRL2.B.ISOCANFDEN =1;
CAN_0.FDCTRL.B.FDRATE=0;
CAN_0.FDCTRL.B.TDCEN=0;
CAN_0.FDCTRL.B.TDCOFF=0;
CAN_0.FDCTRL.B.MBDSR0 = 1;
CAN_0.FDCTRL.B.MBDSR1 = 0;
CAN_0.FDCTRL.B.MBDSR2 = 0;
for (i=0; i<64; i++) { /* MPC574xG has 64 buffers after MPC5748G rev 0*/
CAN_0.MB[i].CS.B.CODE = 0; /* Inactivate all message buffers */
}
//要使用的发送和接受MB初始化
CAN_0.MB[0].CS.B.CODE = txd_inactive; /* Message Buffer 0 set to TX INACTIVE */
CAN_0.MB[1].CS.B.CODE = txd_inactive; /* Message Buffer 1 set to TX INACTIVE , 用MB[1]发送报文*/
CAN0_buf_cs_data(8,rxd_empty,0,0,0,0,0,0);
CAN0_buf_cs_data(9,rxd_empty,0,0,0,0,0,0);
CAN0_buf_cs_data(10,rxd_empty,0,0,0,0,0,0);
CAN0_buf_cs_data(11,rxd_empty,0,0,0,0,0,0);
CAN0_buf_cs_data(12,rxd_empty,0,0,0,0,0,0);
CAN_0.MB[8].ID.B.ID_STD = 0x111;
CAN_0.MB[9].ID.B.ID_STD = 0x112;
CAN_0.MB[10].ID.B.ID_STD = 0x113;
CAN_0.MB[11].ID.B.ID_STD = 0x121;
CAN_0.MB[12].ID.B.ID_STD = 0x115;
CAN_0.RXIMR[8].R = 0xffffffff;
CAN_0.RXIMR[9].R = 0xffffffff;
CAN_0.RXIMR[10].R = 0xffffffff;
CAN_0.RXIMR[11].R = 0xffffffff;
CAN_0.RXIMR[12].R = 0xffffffff;
CAN_0.IMASK1.R = 0X00001F03; // enable interrupt of MB0
INTC.PSR[568].B.PRC_SELN0 = 1; //FLEXCAN0_BUF_00_03的ISR由Z4A核响应
INTC.PSR[570].B.PRC_SELN0 = 1; //FLEXCAN0_BUF_08_11
INTC.PSR[571].B.PRC_SELN0 = 1; //FLEXCAN0_BUF_12_15
INTC.PSR[568].B.PRIN = 7;
INTC.PSR[570].B.PRIN = 8;
INTC.PSR[571].B.PRIN = 8;
SIUL2.MSCR[16].B.SSS = 1; /* Pad PB0: Source signal is CAN0_TX */
SIUL2.MSCR[16].B.OBE = 1; /* Pad PB0: Output Buffer Enable */
SIUL2.MSCR[16].B.SRC = 3; /* Pad PB0: Maximum slew rate */
SIUL2.MSCR[17].B.IBE = 1; /* Pad PB1: Enable pad for input - CAN0_RX */
SIUL2.IMCR[188].B.SSS = 2; /* CAN0_RX: connected to pad PB1 */
//CAN_0.MCR.R = 0x0000003F; /* Negate FlexCAN_0 halt state for 64 MB */
CAN_0.MCR.B.HALT = 0;
CAN_0.MCR.B.FRZ = 0; // disable module to enter freezing mode.
while (CAN_0.MCR.B.FRZACK) {};
while (CAN_0.MCR.B.NOTRDY) {}; /* Wait to clear */
}
void CAN0_TransmitMsg(can0_msg_buf* pbuffer,unsigned char index)
{
unsigned char i=0,DataByteNum=0;
CAN_0.MB[index].CS.B.CODE = txd_inactive; /* Message Buffer 0 set to TX INACTIVE , 用MB[0]发送报文*/
CAN_0.MB[index].CS.B.EDL = pbuffer->EDL ;
CAN_0.MB[index].CS.B.BRS = pbuffer->BRS ;
//CAN_0.MB[index].CS.B.ESI = pbuffer->ESI;
CAN_0.MB[index].CS.B.IDE = pbuffer->ide; /* Use standard ID length */
CAN_0.MB[index].ID.B.ID_STD = pbuffer->std_id; /* Transmit ID is 555 */
CAN_0.MB[index].CS.B.RTR = pbuffer->rtr; /* Data frame, not remote Tx request frame */
if((pbuffer->length)<=8)
DataByteNum = pbuffer->length;
else if((pbuffer->length)==9)
DataByteNum = 12;
else if((pbuffer->length)==10)
DataByteNum = 16;
else if((pbuffer->length)==11)
DataByteNum = 20;
else if((pbuffer->length)==12)
DataByteNum = 24;
else if((pbuffer->length)==13)
DataByteNum = 32;
else if((pbuffer->length)==14)
DataByteNum = 48;
else if((pbuffer->length)==15)
DataByteNum = 64;
for (i=0; i < DataByteNum; i++) {
CAN_0.MB[index].DATA.B[i] = pbuffer->data[i]; /* Data to be transmitted */
}
CAN_0.MB[index].CS.B.DLC = pbuffer->length; /* # bytes to transmit w/o null */
CAN_0.MB[index].CS.B.SRR = 1; /* 发送时,该位为1*/
CAN_0.MB[index].CS.B.CODE =txd_active; /* Activate msg. buf. to transmit data frame */
}
Hi,
I can recommend to check following:
- have the same bit timing setting on both nodes, same sample point
- if FD is enabled (MCR[FDEN]) you should use CAN_CBT register
- be sure your MCU version is really ISO-FD compliant, mask 0N78S
- have proper CAN bus termination
BR, Petr