MPC5744pevb about can receive

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

MPC5744pevb about can receive

1,041 Views
wongdavid
Contributor II

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.

Tags (2)
0 Kudos
4 Replies

697 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

You can just set a mask acceptance register(s) properly, means clear all bits. In that case the received ID is “don’t care”. If you want to receive both standard and extended frames then at least 2 MBs should be set for receive, one for standard (IDE=0) and other for extended frames (IDE=1) (assuming CTRL2[EACEN]=0).

So try to clear CAN_1.RXGMASK.R in your config.

BR, Petr

697 Views
wongdavid
Contributor II

is this set?

CAN_1.MCR.B.MDIS = 1; 
CAN_1.CTRL1.B.CLKSRC=0;
CAN_1.CTRL2.R=0;//set this?
CAN_1.MCR.B.MDIS = 0; 
while (!CAN_1.MCR.B.FRZACK) {}
CAN_1.CTRL1.R = 0x01DB0086;
for(i=0; i<64; i++)
{
CAN_1.MB[i].CS.B.CODE = 0;
}
CAN_1.RXMGMASK.R = 0;//0x1FFFFFFF; /* Global acceptance mask */
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;

CAN_1.MB[4].CS.B.CODE = 4;
CAN_1.MB[4].CS.B.IDE = 1; /* MB 4 will look for a standard ID */

CAN_1.MB[4].ID.B.ID_STD = 0x260;

CAN_1.MB[4].CS.B.CODE = 4;

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

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 */

0 Kudos

697 Views
PetrS
NXP TechSupport
NXP TechSupport

you configure the same MB twice, you need 2 different MBs if you want to receive both standard and extended frames.

BR, Petr

697 Views
wongdavid
Contributor II

You did me a big favor

thank you very much

0 Kudos