MPC5748G FLEXCAN Recieving multiple IDs

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

MPC5748G FLEXCAN Recieving multiple IDs

1,480 Views
wenxiangyock
Contributor I

Hi,

I am trying to communicate between 2 MPC5748G-LCEVB boards, i have a question on how do i enable the message buffer to receive two different sets of different ID. For example, i would like to receive 0x555 and 0x666 as my ID. I studied the example on the MPC5748G Qorivva recipe FLEXCAN chapter and have some questions:

1) For the first initialize function, if i were to initialize for recieving 2 different ID, i will have to use 2 different MB, is that right?

   - IN this case CAN_1.MB[4] and for the second, i could use CAN1.MB[3] ?

2) Do i need to change the CAN_1.RXMGMASK.R value. I understand that this is a global acceptance mask, but does this impact the choice of acceptance of the IDs?

3) Do i need to change CAN_1.IFLAG1.B.BUF4TO1I != 4 for the MB[3]?

3) For the receive function, similarly, do i need to use a separate set of MB to pass the data, ID, length and Code out?

4) Is there anything else i need to set in order for me to receive the particular IDs, example the filtering portion of the message buffer? Do you have a simple example project for receiving multiple IDs? Could you please provide me a simple example?

Thank you.

WX

void initCAN_1(void) {

uint8_t i;

CAN_1.MCR.B.MDIS = 1; 

CAN_1.CTRL1.B.CLKSRC=0; 

CAN_1.MCR.B.MDIS = 0;

while (!CAN_1.MCR.B.FRZACK) {}

CAN_1.CTRL1.R = 0x04DB0086;

for (i=0; i<96; i++)

{

   CAN_1.MB[i].CS.B.CODE = 0; 

}

CAN_1.MB[4].CS.B.IDE = 0; /* 

CAN_1.MB[4].ID.B.ID_STD = 0x555;                       ///<--------------Need to change the IDs and message buffer#  ///

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

CAN_1.RXMGMASK.R = 0x1FFFFFFF; 

...

...

...

...

}

void ReceiveMsg(void) {

   uint8_t j;

   uint32_t dummy;

   while (CAN_1.IFLAG1.B.BUF4TO1I != 8) {};    ////<-----------------Do i need to change this to 4? ////

   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;

CAN_1.IFLAG1.R = 0x00000010;

}

0 Kudos
3 Replies

915 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

If you want to receive just those 2 IDs then either 2 MB must be configured or RX FIFO should be used.

Assume just MBs will be used…

1) Yes, 2 separate MBs will be configured for RX operation with different IDs, e.g MB[4] and MB[3]

2) if global masking is used MCR[IRMQ]=0 then leave RXMGMASK = 0xFFFFFFFF. In this case all bits of received ID are compared with the one initialized in the MB

3) yes, when polling for received message proper MB flag must be checked and respective MB must be read.

4) just configure another MB for receive and use it the same way as it is in the existing examples.  

BR, Petr

0 Kudos

915 Views
wenxiangyock
Contributor I

Hi,

Could you just help me glance through with what is wrong with my initialization and receive function. Basically, i am receiving 2 IDs 0x666 and 0x444 on CAN0, and passing them to mail box MB[4] and MB[3] respectively, so upon receiving either one they are supposed to print out the information. I am unable to receive 0x444 but instead able to receive 0x666. I checked regarding the masking is written correctly and the CAN0_MCR.B.IRMQ = 0 has been set as instructed.  

Thank you.

Regards,

WX

void initCAN_0_rx(void) { 
   uint8_t i;

   CAN_0.MCR.B.MDIS = 1;
   CAN_0.CTRL1.B.CLKSRC=0; 
   CAN_0.MCR.B.MDIS = 0; 
   CAN_0.MCR.B.IRMQ = 0;

   while (!CAN_0.MCR.B.FRZACK) {}
   CAN_0.CTRL1.R = 0x04DB0086; 
   for (i=0; i<96; i++)

    { 
      CAN_0.MB[i].CS.B.CODE = 0; 
    }


   CAN_0.MB[4].CS.B.IDE = 0; 
   CAN_0.MB[4].ID.B.ID_STD = 0x666; 
   CAN_0.MB[4].CS.B.CODE = 4; 

   CAN_0.MB[3].CS.B.IDE = 0; 
   CAN_0.MB[3].ID.B.ID_STD = 0x444; 
   CAN_0.MB[3].CS.B.CODE = 4;
   CAN_0.RXMGMASK.R = 0x1FFFFFFF;

   SIUL2.MSCR[16].B.SSS = 1; 
   SIUL2.MSCR[16].B.OBE = 1; 
   SIUL2.MSCR[16].B.SRC = 3;
   SIUL2.MSCR[17].B.IBE = 1; 
   SIUL2.IMCR[188].B.SSS = 2; 

   CAN_0.MCR.R = 0x0000003F;
   while (CAN_0.MCR.B.FRZACK & CAN_0.MCR.B.NOTRDY) {} 

}

char* ReceiveMsg(void) {                                       //////*-------------- FUNCTION TO RECEIVE FOR MB[4] ----------------------*/////
   uint8_t j;
   uint32_t __attribute__ ((unused)) dummy;


   int size;
   char combinepacket[20] = {} ; 
/*-------------------------------------------------------------MB[4]-----------------------------------------------*/
   while (CAN_0.IFLAG1.B.BUF4TO1I != 8) {};
   RxCODE = CAN_0.MB[4].CS.B.CODE; 
   RxID = CAN_0.MB[4].ID.B.ID_STD; 
   RxLENGTH = CAN_0.MB[4].CS.B.DLC;

   for (j=0; j<RxLENGTH; j++)

   {
      RxDATA[j] = CAN_0.MB[4].DATA.B[j]; 
   }

/* DO SOME STUFF HERE  (PRINT INFO)*/ 

   RxTIMESTAMP = CAN_0.MB[4].CS.B.TIMESTAMP;

   dummy = CAN_0.TIMER.R; 
   CAN_0.IFLAG1.R = 0x00000010; 

   if(RxDATA[0] == 'H')

   {
      SIUL2.MSCR[PA10].B.OBE = 1; 
   }

   return 0;

}

char* ReceiveMsg1(void) {                                       //////*-------------- FUNCTION TO RECEIVE FOR MB[3] ----------------------*/////
   uint8_t j;
   uint32_t __attribute__ ((unused)) dummy;


   int size;
   char combinepacket1[20] = {} ; 
/*-------------------------------------------------------------MB[3]-----------------------------------------------*/
   while (CAN_0.IFLAG1.B.BUF4TO1I != 4) {};
   RxCODE1 = CAN_0.MB[3].CS.B.CODE; 
   RxID1 = CAN_0.MB[3].ID.B.ID_STD; 
   RxLENGTH1 = CAN_0.MB[3].CS.B.DLC;

   for (j=0; j<RxLENGTH1; j++)

   {
      RxDATA1[j] = CAN_0.MB[3].DATA.B[j]; 
   }

/* DO SOME STUFF HERE  (PRINT INFO)*/ 

   RxTIMESTAMP1 = CAN_0.MB[3].CS.B.TIMESTAMP;

   dummy = CAN_0.TIMER.R; 
   CAN_0.IFLAG1.R = 0x00000008; 

   if(RxDATA1[0] == 'H')

   {
      SIUL2.MSCR[PA10].B.OBE = 1; 
   }

   return 0;

}

0 Kudos

915 Views
PetrS
NXP TechSupport
NXP TechSupport

If you periodically call both Receive functions, then there should be no issue. The MB[3] should be filled with message with ID 0x444.

Do you see both flags set in the IFLAG1 register?

Maybe try different flag checking statement...

while ((CAN_0.IFLAG1.B.BUF4TO1I & 0x8) != 0x8) {};  //for MB4

while ((CAN_0.IFLAG1.B.BUF4TO1I & 0x4) != 0x4) {};  //for MB3

or within your main function use

if(CAN_0.IFLAG1.R & 0x10) ReceiveMsg();

if(CAN_0.IFLAG1.R & 0x8) ReceiveMsg1();

Then within ReceiveMsg function while statement is not needed.

BR, Petr

0 Kudos