AnsweredAssumed Answered

S32K148 CAN receiver without filtering

Question asked by Tomas Frcek on Jan 15, 2018
Latest reply on Jan 16, 2018 by Tomas Frcek

Hello,

 

I'm trying to implement a CAN receiver that accepts all CAN messages (all IDs without filtering). With my current software I'm able to transmit CAN messages, but can only receive CAN messages for which I specify the ID in the receive Message Buffer (MB).

 

void FLEXCAN0_Init(void)

{

   // CLK for FlexCAN.
    PCC->PCCn[PCC_FlexCAN0_INDEX] |= 0x1 << 30 /* CGC */;
    
    // Deactivate FlexCAN module.
    CAN0->MCR |= 0x1U << 31 /* MDIS */;
    
    // CAN Protocol Engine CLK source set to SOSCDIV2_CLK.
    CAN0->CTRL1 &= ~(0x1 << 13 /* CLKSRC */);
    
    // Activate FlexCAN module. Also sets FRZ and HALT flags.

    CAN0->MCR &= ~(0x1U << 31 /* MDIS */);
    
    // Wait for FRZACK.
    while ((CAN0->MCR & (0x1 << 24 /* FRZACK */)) == 0x0) { ; }

 

   // Setup bit timing for 500 kbps CAN.

   CAN0->CTRL1 = 0x3 | 0x2 << 16 | 0x7 << 19 | 0x2 << 22;

 

   // Clear all MBs.

   for (i = 0; i < 128; i++)
    {
        CAN0->RAMn[i] = 0x0;
    }

 

   // Deassert all individual mask bits for all MBs.

   for(i = 0; i < 16; i++)
   {     
      CAN0->RXIMR[i] = ~(0xFFFFFFFF);
   }

 

   // Setup MBs 4 and 5 to receive Standard ID CAN messages.

   for (int i = 4; i < 6; i++)
   {
       CAN0->RAMn[i * 4 + 0] = 0x4 << 24 /* CODE = 4 - MB is empty and free to receive. */;
   }
 

   // Setup MBs 6 and 7 to receive Extended ID CAN messages.
   for (int i = 6; i < 8; i++)
   {
        CAN0->RAMn[i * 4 + 0] = (0x4 << 24) /* CODE = 4 - MB is empty and free to receive. */ | (0x1 << 21) /* MB to receive extended IDs. */

    }

 

   // Last MB used is MB7.

   CAN0->MCR = 0x7;

 

   while ((CAN_MCR_FRZACK_MASK && CAN0->MCR) >> CAN_MCR_FRZACK_SHIFT)  {}

   while ((CAN_MCR_NOTRDY_MASK && CAN0->MCR) >> CAN_MCR_NOTRDY_SHIFT)  {}

}

 

Using this FlexCAN configuration I'm not able to receive any message. If I specify a message ID into a MB set to receive, than I receive this message with no problems. But I want to shut down the filtering function entirely so that I can receive CAN messages with any ID.

Outcomes