S32K146: RX Message Buffer Configuration for multiple CAN ID's

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K146: RX Message Buffer Configuration for multiple CAN ID's

2,305 Views
shahenshah
Contributor II

S32k146: How to configure Message Buffer in CAN for multiple CAN ID's. Is there any reference or example code that I can refer to for the configuration of MBs with classical CAN?

6 Replies

2,134 Views
shahenshah
Contributor II

Hi Petr

I appreciate & thanks for your support.

After modifying the number of Rxmailbox to 13,  still  I am not getting execution in the callback. Is there any specific required to enable callback function?

0 Kudos

2,134 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

try to use attached code. It is working on my S32K146EVB.

BR, Petr

0 Kudos

2,134 Views
shahenshah
Contributor II

Hi Petr

Thanks for your response.

CAN communication is working but still, I am not getting the in CALLBACK function.

The problem that I am facing right now, execution is not going in the callback function whenever I am receiving or transmitting any data using CAN0.

Whenever I add a breakpoint in the callback function mentioned below, the execution doesn't stop in callback function 

void CAN_0_Rx_Callback(uint8_t instance, can_event_t eventType, uint32_t buffIdx, void *driverState)
{

   switch(eventType)
   {
      case CAN_EVENT_RX_COMPLETE:
            PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));

            break;

      case CAN_EVENT_TX_COMPLETE:
            PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));

            break;
      }

}

0 Kudos

2,134 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if you want to receive messages with specific ID range or all IDs into single MB then set accordingly the mask acceptance register.

The acceptance mask registers are used to filter incoming ID. There is bit2bit correspondence between received ID, mask and programmed MB ID (or RXFIFO ID filter elements). The mask says if corresponding incoming ID bit is compared with programmed ID bit.

If mask bit is cleared the incoming ID bit is not compared, it is don’t care. If mask bit is set, then there must be exact match between incoming ID bit and programmed ID bit. To receive a message into a MB/RXFIFO all relevant bits with mask bit set must be equal to programmed one.

 

There are following rules for message filtering for different FlexCAN module configuration (assume module with 32 MBs)

a) When MCR[FEN]=0, no RX FIFO

   MCR[IRMQ]=0: MB0-MB31 use RXGMASK except MB14 uses RX14MASK and MB15 used RX15MASK

   MCR[IRMQ]=1: MB0-MB31 use RXIMR0-RXIMR31

 

b) When MCR[FEN]=1, RX FIFO used

   MCR[IRMQ]=0: all RX FIFO ID elements uses RXFGMASK, rest of MBs use RXGMASK except MB14 uses RX14MASK and MB15 used RX15MASK (only if MB14/15 are not occupied by RXFIFO ID table)

   MCR[IRMQ]=1: RX FIFO ID elements uses RXIMRx and RXFGMASK depending the CTRL2[RFFN] setting

Simple CAN examples are available within S32 Design Studio.

 

BR, Petr

2,134 Views
shahenshah
Contributor II

Hi Petr

Thanks for sharing the detailed information.

I am using RX message buffers i.e. 10,11 & 12 and trying to install callback but i am not understanding where my code is going wrong? I am not getting execution in the callback.I am using LPtimer for setting sendFrame flag, which is working fine.

I have attached all the related files for reference.

#define TX_MAILBOX (1UL)
#define TX_MSG_ID (1UL)
#define RX_MAILBOX (0UL)
#define RX_MAILBOX10 (10UL) // MB10
#define RX_MAILBOX11 (11UL) // MB11
#define RX_MAILBOX12 (12UL) // MB12

#define VCU_HMI_CAN_TX_PCKT_1 0x18FD3DF9

#define HMI_VCU_CAN_RX_PCKT_1 0x18EF3D2D
#define HMI_VCU_CAN_RX_PCKT_2 0x18EE3D2D 
#define HMI_VCU_CAN_RX_PCKT_3 0x18ED3D2D

void lptmrISR(void)
{
/* Clear compare flag */
LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
sendFrame = true;
}

void LP_Periodic_Timer_init(void)
{
LPTMR_DRV_Init(INST_LPTMR1, &lpTmr1_config0, false);

/* Install IRQ handler for LPTMR interrupt */
INT_SYS_InstallHandler(LPTMR0_IRQn, &lptmrISR, (isr_t *)0);
/* Enable IRQ for LPTMR */
INT_SYS_EnableIRQ(LPTMR0_IRQn);

/* Start LPTMR counter */
LPTMR_DRV_StartCounter(INST_LPTMR1);
}

void Can_init(void)
{
CAN_Init(&can_pal1_instance, &can_pal1_Config0);

can_buff_config_t buffCfg = {
//.enableFD = true,
.enableFD = false,
//.enableBRS = true,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_EXT,
.isRemote = false
};
/* Configure RX buffer with index RX_MAILBOX */


// Message Buffer10(MB10) configured for HMI_VCU_CAN_RX_PCKT_1 ID i.e 0x18EF3D2D
CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX10, &buffCfg, HMI_VCU_CAN_RX_PCKT_1);
// Message Buffer11(MB11) configured for HMI_VCU_CAN_RX_PCKT_2 ID i.e 0x18EE3D2D
CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX11, &buffCfg, HMI_VCU_CAN_RX_PCKT_2);
// Message Buffer12(MB12) configured for HMI_VCU_CAN_RX_PCKT_3 ID i.e 0x18ED3D2D
CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX12, &buffCfg, HMI_VCU_CAN_RX_PCKT_3);


//Generaic Buffer..no specific mailbox selected for any id
// CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &buffCfg, NULL);


// CAN_ConfigTxBuff(&can_pal1_instance, TX_MAILBOX, &buffCfg);
CAN_InstallEventCallback(&can_pal1_instance, (can_callback_t)CAN_0_Rx_Callback, NULL);

}


void CAN_0_Rx_Callback(uint8_t instance, can_event_t eventType, uint32_t buffIdx, void *driverState)
{
can_event_t salim= eventType;

}

//Main Function

int main(void)
{
   /* Do the initializations required for this application */
   BoardInit();
   GPIOInit();
   Can_init();
   LP_Periodic_Timer_init();

   while(1)
   {

      if (sendFrame==true)
      {

      CAN_ConfigTxBuff(&can_pal1_instance, TX_MAILBOX, &buffCfg);
         // Prepare message to be sent
         can_message_t message = {
         .cs = 0U,
         .id = VCU_HMI_CAN_TX_PCKT_1,

         .data = { 0x58, 0x64, 0x01, 0x02 },
         .length = 8U
            };

            // Send the information via CAN
            CAN_Send(&can_pal1_instance, TX_MAILBOX, &message);

            /* Wait until the previous FlexCAN transmit is completed */
               while(CAN_GetTransferStatus(&can_pal1_instance, TX_MAILBOX) == STATUS_BUSY);                
               PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));
               sendFrame = false;


         }// End of if loop


         // Define receive buffer
         can_message_t recvMsg;

         // Start receiving data in RX_MAILBOX.
         CAN_Receive(&can_pal1_instance, RX_MAILBOX10, &recvMsg);

            PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));

}// End of infinite loop

0 Kudos

2,134 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

within CAN component increase number of used MBs, if you want to use MB12 set value to 13

pastedImage_1.png

BR, Petr