problem with MPC5634's CAN

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

problem with MPC5634's CAN

621 Views
xiaofangu
Contributor III

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!

0 Kudos
1 Reply

506 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

CAN code looks normal. If ReceiveMsg() is called from MB interrupt, then I expect it should work.

Most probably the issue comes from something else.

BR, Petr

0 Kudos