AnsweredAssumed Answered

MPC5744pevb about can receive

Question asked by wong david on Oct 24, 2017
Latest reply on Oct 25, 2017 by wong david

in the example,the flexcan can  communicate with ID=0X555,but it can only communite with the initCAN_1()'s ID,and if i changed ID,the communication will get stucked.

here is the init

void initCAN_1(void) { /* General init. MB IDs: MB4 ID_STD=0x555 */
uint8_t i;

CAN_1.MCR.B.MDIS = 1; /* Disable module before selecting clock source*/
CAN_1.CTRL1.B.CLKSRC=0; /* Clock Source = oscillator clock (16MHz) */
CAN_1.MCR.B.MDIS = 0; /* Enable module for config. (Sets FRZ, HALT)*/
while (!CAN_1.MCR.B.FRZACK) {} /* Wait for freeze acknowledge to set */
/* Good practice: wait for FRZACK on freeze mode entry/exit */
CAN_1.CTRL1.R = 0x01DB0086; /* CAN bus: same as for CAN_0 */

//for (i=0; i<96; i++) { /* MPC574xG has 96 buffers after MPC5748G rev 0*/
for(i=0; i<64; i++)
{
CAN_1.MB[i].CS.B.CODE = 0; /* Inactivate all message buffers */
}
CAN_1.MB[4].CS.B.IDE = 0; /* MB 4 will look for a standard ID */
CAN_1.MB[4].ID.B.ID_STD = 0x1C2; /* MB 4 will look for ID = 0x555 */ /*here is init ID*/
CAN_1.MB[4].CS.B.CODE = 4; /* MB 4 set to RX EMPTY */
CAN_1.RXMGMASK.R = 0x1FFFFFFF; /* Global acceptance mask */

/* Configure CAN1_TX pin. PA14. */
SIUL2.MSCR[PA14].B.SSS = 1; //Select output source as CAN1_TX
SIUL2.MSCR[PA14].B.SRC = 3; //Set to full drive strength without slew rate control
SIUL2.MSCR[PA14].B.OBE = 1; //Enable output buffer

/* Configure CAN1_RX pin. PA15. */

SIUL2.MSCR[PA15].B.IBE = 1; //Set PA15 to input
SIUL2.IMCR[33].B.SSS = 0b0001; //Point CAN1_RX to pin PA15

CAN_1.MCR.R = 0x0000003F; /* Negate FlexCAN 1 halt state for 64 MBs */
while (CAN_1.MCR.B.FRZACK & CAN_1.MCR.B.NOTRDY) {} /* Wait to clear */
/* Good practice: wait for FRZACK on freeze mode entry/exit */
}

 

here is receive

void CAN_1_ReceiveMsg(void) {
uint8_t j;
uint32_t dummy;

while (CAN_1.IFLAG1.B.BUF4TO1I != 8) {}; /* Wait for CAN 1 MB 4 flag */ /*will get stucked if i change the input message ID*/
RxCODE = CAN_1.MB[4].CS.B.CODE; /* Read CODE, ID, LENGTH, DATA, TIMESTAMP*/
RxID = CAN_1.MB[4].ID.B.ID_STD;
RxLENGTH = CAN_1.MB[4].CS.B.DLC;
for (j=0; j<RxLENGTH; j++) {
RxDATA[j] = CAN_1.MB[4].DATA.B[j];
}

RxTIMESTAMP = CAN_1.MB[4].CS.B.TIMESTAMP;
dummy = CAN_1.TIMER.R; /* Read TIMER to unlock message buffers */
if(dummy){}
CAN_1.IFLAG1.R = 0x00000010; /* Clear CAN 1 MB 4 flag */

if(RxDATA[0]== 0x00)
{
SIUL2.MSCR[PC11].B.OBE = 1; //PC11 (Red LED) set to output

}
}

 

the example's function are defined to one to one communication,but i need receive port can receive any different ID.so what should i do .

think you.

Outcomes