MPC5606B Receiving all CAN IDs

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MPC5606B Receiving all CAN IDs

跳至解决方案
1,514 次查看
fscheidl
Contributor II

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); }
标签 (1)
1 解答
1,172 次查看
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 2 MBs should be set for receive, one for standard and other for extended frames.

BR, Petr

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,172 次查看
ruudsiebierski
Contributor III

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

0 项奖励
回复
1,172 次查看
PetrS
NXP TechSupport
NXP TechSupport

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.

pastedImage_1.png

BR, Petr

1,172 次查看
ruudsiebierski
Contributor III

Hi Petr,

Thank you for the answer, tested it and it worked, of course!

Too bad this functionality (setting the bit in the CTRL2 register) is not exposed in the SDK driver.

BR,

Ruud

0 项奖励
回复
1,173 次查看
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 2 MBs should be set for receive, one for standard and other for extended frames.

BR, Petr

0 项奖励
回复