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); }
已解决! 转到解答。
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 2 MBs should be set for receive, one for standard and other for extended frames.
BR, Petr
Hi Petr,
I had the same question but for the MPC5748G target. We found out that we also need 1 MB for regular ID and 1 for extended ID. Why is this necessary?
It makes receiving all CAN data a bit more difficult, starting 2 receives at the same time.
BR,
Ruud
Hi Ruud,
on the MPC5748G you have an option to receive both standard and extended ID messages into single MB.
Just set CTRL2[EACEN] bit and clear all bits in mask register.
The EACEN enables the comparison of both Rx Mailbox filter’s IDE and RTR bit with their corresponding bits
within the incoming frame. Mask bits do apply.
BR, Petr
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 2 MBs should be set for receive, one for standard and other for extended frames.
BR, Petr