AnsweredAssumed Answered

MPC5606B Receiving all CAN IDs

Question asked by fscheidl on Feb 11, 2016
Latest reply on Feb 11, 2016 by Petr Stancik

I am trying to receive all possible (standard) CAN IDs with one FlexCAN module on MPC5606B.

 

At the moment, I am using the following code, that, unfortunately, only works for receiving messages with one single CAN ID (see SetCanRxFilter). Is it possible to receive all CAN IDs on one message buffer or do I have to switch to RxFIFO instead of CAN Mailboxes? Is there any example code for receiving any CAN messages with arbitrary IDs?

 

Thank you very much in advance!

 

void SetCanRxFilter(uint32_t id, uint8_t mb, uint8_t ext)  {     if (ext)     {         CAN_1.BUF[mb].CS.B.IDE = 1;/* MB for extended ID */         CAN_1.BUF[mb].ID.R = id;   /* MB ID */     }     else     {         CAN_1.BUF[mb].CS.B.IDE = 0; /* MB for standard ID */         CAN_1.BUF[mb].ID.B.STD_ID = (uint16_t)id; /* MB ID */     }     CAN_1.BUF[mb].CS.B.CODE = CAN_RX_EMPTY; /* Set rx MB empty */ }  can_msg_struct CanRxMsg (uint8_t mb) {   uint8_t i;   uint32_t dummy;   uint32_t flagIFRL = 0;   uint32_t flagIFRH = 0;   can_msg_struct msg;     if (mb < 32)   {     flagIFRL = ((uint32_t)(0x00000001 << mb));   }   else   {     flagIFRH = ((uint32_t)(0x00000001 << (mb - 32)));   }       msg.code   = (uint8_t)CAN_1.BUF[mb].CS.B.CODE;     if (CAN_1.BUF[0].CS.B.IDE) /* if extended ID */     {         msg.id  = CAN_1.BUF[mb].ID.R;     }     else /* if standard ID */     {         msg.id  = (uint16_t)CAN_1.BUF[mb].ID.B.STD_ID;     }     msg.length = (uint8_t)CAN_1.BUF[mb].CS.B.LENGTH;     for (i = 0; i < msg.length; i++)      {          msg.data[i] = CAN_1.BUF[mb].DATA.B[i];     }     dummy = CAN_1.TIMER.R;  /* Read TIMER to unlock MB */         CAN_1.IFRL.R = flagIFRL; /* Clear MB flag */     CAN_1.IFRH.R = flagIFRH; /* Clear MB flag */     return (msg); }

Outcomes