AnsweredAssumed Answered

problem with MPC5634's CAN

Question asked by xiaofan gu on Jul 4, 2018

Hello,

   I have confronted a problem with CANmodule, my CAN receiver function can receive several times of CAN frame successfully,and then the program runs away.

   My code is:

void InitCAN_A(void)
{
uint8_t i;
CAN_A.MCR.R = 0x5000003F; /* Put in Freeze Mode & enable all 64 msg bufs */
/* Use 1 of the next 2 lines depending on crystal frequency: */
CAN_A.CR.R = 0x03D10001; /* Configure for 8MHz OSC, 250K  0x03D10001*/

for (i=0; i<64; i++)
{
CAN_A.BUF[i].CS.B.CODE = 0; /* Inactivate all message buffers */
}
CAN_A.BUF[0].CS.B.CODE = 8; /* Message Buffer 0 set to TX INACTIVE */

CAN_A.BUF[5].CS.B.IDE = 0; /* MB 5 will look for a standard ID */
CAN_A.BUF[5].ID.B.STD_ID = 0x200; /* MB 5 will look for ID = 0x200 */
CAN_A.BUF[5].CS.B.CODE = 4; /* MB 5 set to RX EMPTY */
CAN_A.RXGMASK.R = 0x1FFFFFFF; /* Global acceptance mask */
CAN_A.IMRL.B.BUF05M = 1; /*Enable MB5 receive interrupt*/
INTC.PSR[160].B.PRI = 8;
SIU.PCR[83].R = 0x0604; /* MPC56xxM: Config port GPIO[83] as CAN0TX 0x0604*/
SIU.PCR[84].R = 0x0500; /* MPC56xxM: Configure port GPIO[84] as CAN0RX */
CAN_A.MCR.R = 0x0000003F; /* Negate FlexCAN 0 halt state for 64 MB */
}

void ReceiveMsg(void) {
uint8_t j;
uint32_t dummy;
//while (CAN_A.IFRL.B.BUF05I == 0) {}; /* Wait for CANA MB 5 flag */
RxCODE = CAN_A.BUF[5].CS.B.CODE; /* Read CODE, ID, LENGTH, DATA, TIMESTAMP*/
RxID = CAN_A.BUF[5].ID.B.STD_ID;
RxLENGTH = CAN_A.BUF[5].CS.B.LENGTH;
for (j=0; j<RxLENGTH; j++) {
RxDATA[j] = CAN_A.BUF[5].DATA.B[j];
}
RxTIMESTAMP = CAN_A.BUF[5].CS.B.TIMESTAMP;
dummy = CAN_A.TIMER.R; /* Read TIMER to unlock message buffers */
if(dummy){}
// XcpCan_RxCallback(RxID,RxLENGTH,RxDATA);
CAN_A.IFRL.R = 0x00000020; /* Clear CANA MB 5 flag */
}

And my environment is :

IDE:S32DS.Power.2017.R1

EVB:XCP56XX EVB MOTHERBOARD Rev.C + XCP563M 144QFP MINI-MODULE

 

Any help will be appreciated!

Outcomes