<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to set up receiving on multiple CAN interfaces in MPC5xxx</title>
    <link>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1334781#M19065</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;yes, each module has 96MBs.&lt;BR /&gt;Single task could work I think, but you should wait for driver status or use interrupt to know when to read/use received data and prepare MB for new reception. Manipulating with IFLAG and MASK register is not recommended, it is done within driver. &lt;BR /&gt;You can try to prepare MB for reception (calling&amp;nbsp;&amp;nbsp;FLEXCAN_DRV_ConfigRxMb with&amp;nbsp;FLEXCAN_DRV_Receive) before scheduler is started or in some init task. Then in your RX task you can do&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for ( ;; )&lt;BR /&gt;{&lt;BR /&gt;/* Define receive buffer */&lt;BR /&gt;flexcan_msgbuff_t recvBuff1, recvBuff2;&lt;/P&gt;
&lt;P&gt;/* if the previous FlexCAN receive is completed */&lt;BR /&gt;if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX1) &amp;lt;&amp;gt; STATUS_BUSY)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;// read&amp;nbsp;recvBuff1 data as needed&lt;BR /&gt;&amp;nbsp; &amp;nbsp;/* Start receiving data in RX_MAILBOX1 again. */&lt;BR /&gt;&amp;nbsp; &amp;nbsp;FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX1, &amp;amp;recvBuff1);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM2, RX_MAILBOX2) &amp;lt;&amp;gt; STATUS_BUSY)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;// read&amp;nbsp;recvBuff2 data as needed&lt;BR /&gt;&amp;nbsp; &amp;nbsp;/* Start receiving data in RX_MAILBOX2 again. */&lt;BR /&gt;&amp;nbsp; &amp;nbsp;FLEXCAN_DRV_Receive(INST_CANCOM2, RX_MAILBOX2, &amp;amp;recvBuff2);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Could be a question if you do not miss some messages this way, depends on bus load.&lt;/P&gt;
&lt;P&gt;BR, Petr&lt;/P&gt;</description>
    <pubDate>Fri, 03 Sep 2021 10:15:32 GMT</pubDate>
    <dc:creator>PetrS</dc:creator>
    <dc:date>2021-09-03T10:15:32Z</dc:date>
    <item>
      <title>How to set up receiving on multiple CAN interfaces</title>
      <link>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1333575#M19041</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;I need to develop an application that receives messages on two CAN modules. I am using freeRTOS and would like to make it as easy as possible.&lt;BR /&gt;I was considering if using simple SDK functions in a single task would work - they are supposed to be non-blocking.&lt;BR /&gt;I was thinking about something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    uint8_t rx_mailbox1 = 1;
    uint8_t rx_mailbox2 = 2;
    
    // Set information about the data to be received
    flexcan_data_info_t dataInfo =
    {
            .data_length = 1U, //don't care - larger msgs are also received
            .msg_id_type = FLEXCAN_MSG_ID_STD,
            .enable_brs  = false,
            .fd_enable   = false,
            .fd_padding  = 0U
    };

    // Configure RX message buffer
    FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, rx_mailbox1, &amp;amp;dataInfo, 1);
    FLEXCAN_DRV_ConfigRxMb(INST_CANCOM2, rx_mailbox2, &amp;amp;dataInfo, 1);

    // set the Mask to receive all the messages
    FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0);
    FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM2, FLEXCAN_MSG_ID_STD, 0);

    while(1){
        // Define receive buffer
        flexcan_msgbuff_t recvBuff1, recvBuff2;

        FLEXCAN_DRV_Receive(INST_CANCOM1, rx_mailbox1, &amp;amp;recvBuff);
        FLEXCAN_DRV_Receive(INST_CANCOM2, rx_mailbox2, &amp;amp;recvBuff);

	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this doesn't work I was thinking about using the interrupt flags to monitor any changes on the message buffers. However, I am not really sure if this approach could work.&lt;BR /&gt;My idea is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;  uint8_t rx_mailbox1 = 1;
  uint8_t rx_mailbox2 = 2;

  // Set information about the data to be received
   flexcan_data_info_t dataInfo =
   {
      .data_length = 1U, //don't care - larger msgs are also received
      .msg_id_type = FLEXCAN_MSG_ID_STD,
      .enable_brs  = false,
      .fd_enable   = false,
      .fd_padding  = 0U
    };

    // Configure RX message buffer
    FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, rx_mailbox1, &amp;amp;dataInfo, 1);
    FLEXCAN_DRV_ConfigRxMb(INST_CANCOM2, rx_mailbox2, &amp;amp;dataInfo, 1);

    // set the Mask to receive all the messages
    FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0);
    FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM2, FLEXCAN_MSG_ID_STD, 0);

    //enable interrupts for all the message buffers on two CANs
    CAN0-&amp;gt;IMASK1 |= CAN_IMASK1_BUF31TO0M_MASK; //for INST_CANCOM1 Interface
    CAN1-&amp;gt;IMASK1 |= CAN_IMASK1_BUF31TO0M_MASK; //for INST_CANCOM2 Interface 

while(1){
        flexcan_msgbuff_t recvBuff1, recvBuff2;

	//check for a flag 
 	if (*CAN0-&amp;gt;IFLAG1 = 0x1){ //something on CAN0 
		FLEXCAN_DRV_Receive(INST_CANCOM1, rx_mailbox, &amp;amp;recvBuff);
                CAN0-&amp;gt;IFLAG &amp;amp;= 0x0; //clear the flag
	}else if(*CAN1-&amp;gt;IFLAG1 = 0x2){ //something on CAN1
		FLEXCAN_DRV_Receive(INST_CANCOM2, rx_mailbox2, &amp;amp;recvBuff);
                CAN1-&amp;gt;IFLAG &amp;amp;= 0x0; //clear the flag
	}
	vTaskDelay(0)
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;However, I have few concerns:&lt;BR /&gt;- does every CAN instance have 96 Message Buffers? Or are there 96 MB in general?&lt;BR /&gt;- are Message Buffers in this case correctly assigned to Mailboxes?&lt;BR /&gt;- the whole code is located in a Task, however, the two comparisons are actually blocking calls. Would an interrupt routine be better?&lt;BR /&gt;- how come the CAN message ID needs to be set up BEFORE receiving a CAN message?&lt;BR /&gt;- do I need to enter any special mode to manipulate the IFLAG and IMASK registers?&lt;/P&gt;&lt;P&gt;And maybe the first approach is simply better?&lt;BR /&gt;Thanks for any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 22:48:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1333575#M19041</guid>
      <dc:creator>pmrlcbtcphtzjdq</dc:creator>
      <dc:date>2021-09-01T22:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to set up receiving on multiple CAN interfaces</title>
      <link>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1334781#M19065</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;yes, each module has 96MBs.&lt;BR /&gt;Single task could work I think, but you should wait for driver status or use interrupt to know when to read/use received data and prepare MB for new reception. Manipulating with IFLAG and MASK register is not recommended, it is done within driver. &lt;BR /&gt;You can try to prepare MB for reception (calling&amp;nbsp;&amp;nbsp;FLEXCAN_DRV_ConfigRxMb with&amp;nbsp;FLEXCAN_DRV_Receive) before scheduler is started or in some init task. Then in your RX task you can do&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for ( ;; )&lt;BR /&gt;{&lt;BR /&gt;/* Define receive buffer */&lt;BR /&gt;flexcan_msgbuff_t recvBuff1, recvBuff2;&lt;/P&gt;
&lt;P&gt;/* if the previous FlexCAN receive is completed */&lt;BR /&gt;if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX1) &amp;lt;&amp;gt; STATUS_BUSY)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;// read&amp;nbsp;recvBuff1 data as needed&lt;BR /&gt;&amp;nbsp; &amp;nbsp;/* Start receiving data in RX_MAILBOX1 again. */&lt;BR /&gt;&amp;nbsp; &amp;nbsp;FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX1, &amp;amp;recvBuff1);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM2, RX_MAILBOX2) &amp;lt;&amp;gt; STATUS_BUSY)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;// read&amp;nbsp;recvBuff2 data as needed&lt;BR /&gt;&amp;nbsp; &amp;nbsp;/* Start receiving data in RX_MAILBOX2 again. */&lt;BR /&gt;&amp;nbsp; &amp;nbsp;FLEXCAN_DRV_Receive(INST_CANCOM2, RX_MAILBOX2, &amp;amp;recvBuff2);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Could be a question if you do not miss some messages this way, depends on bus load.&lt;/P&gt;
&lt;P&gt;BR, Petr&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 10:15:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1334781#M19065</guid>
      <dc:creator>PetrS</dc:creator>
      <dc:date>2021-09-03T10:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to set up receiving on multiple CAN interfaces</title>
      <link>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1342568#M19190</link>
      <description>&lt;P&gt;thanks, I will try it some time later on&lt;/P&gt;</description>
      <pubDate>Sun, 19 Sep 2021 18:53:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/How-to-set-up-receiving-on-multiple-CAN-interfaces/m-p/1342568#M19190</guid>
      <dc:creator>pmrlcbtcphtzjdq</dc:creator>
      <dc:date>2021-09-19T18:53:34Z</dc:date>
    </item>
  </channel>
</rss>

