当前位置:   article > 正文

c#file过滤多种格式_S32K 配置CAN过滤器

#define tx_mailbox_can0 (1ul)

S32K CAN的Mask和过滤器设置方法,如何为下面的场景设置过滤器?

启用了 RX FIFO,将消息发送到CAN网络中,消息ID在0x402-0x450之间。希望CAN网络能够允许除了两个消息ID:0x44d和0x44e的所有信息传递。

解答:

使用如下的配置,RXFIFO只接受0x402-0x450范围内的标准ID,除了ID 0x44d和0x44e。

CAN_MCR[IRMQ]位确定哪个掩码寄存器用于RXFIFO ID表中。

如果CAN_MCR[IRMQ]=0,则所有ID表都受RXFGMASK的影响。

如果CAN_MCR[IRMQ]=1,根据CTRL2[RFFN]的设置,ID表中的组件受单个掩码寄存器(RXIMRx)的影响。

接收到的ID、MASK与已编程的MB ID或ID 表中的元素之间存在位对应关系。掩码表示是否将相应的输入ID位与编程的ID位进行比较。

直接设置单个掩码寄存器需要将flexcan模块设置为冻结模式。

如果置位了Mask位,则传入的ID位和已编程的ID位之间必须精确匹配。要将消息接收到MB/rxfio中,掩码位设置的所有位必须等于已编程的位。

因此,假定上述情况,应该在ID表中混合使用专用ID和ID范围配置。假设CTRL2[RFFN]=1,可以使用下面的配置。(配置的CTRL2[RFFN]=1,根据参考手册,这意味着RX FIFO滤波器元件的数量为16)。注意:如果一个筛选器保持为0,则表示接受所有ID。

5035986388acaacde0bf8f573f2edd6a.png

SDK函数FLEXCAN_DRV_SetRxIndividualMask无法为RXIDB_0/RXIDB_1标识符设置不同的掩码,因此无法轻松使用ID范围的方式。除非将正确的值直接写入RXIMRx寄存器。

使用调试器检查ID筛选表中的ID和掩码寄存器中的Mask是否根据IDE位进行了正确移位。对于标准ID,ID和掩码左移19位;对于扩展ID,设置IDE,ID和掩码左移1位。 使用下面的代码来正确设置Mask寄存器。

uint16_t IDmask[10]=

{0x7FF,0x7FF,0x7FC,0x7F8,0x7F0,0x7F0,0x7F0,0x7F8,0x7FF,0x7FF};

//上表中 ID组件 3的Mask 应该设置为0x7F8,而不是0x7F0。

//此外,Mask寄存器中的位30必须置位,进行IDE位检查,否则也将接收一些扩展的ID。RTR 31位屏蔽应该是有效的。

/*设置单个Mask类型*/

FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_INDIVIDUAL);

for(id_counter=0;id_counter<10;id_counter++)

FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1,FLEXCAN_MSG_ID_STD,id_counter,0xc000000 | IDmask[id_counter]);

/*其余的过滤项用RXFGMASK屏蔽*/

FLEXCAN_DRV_SetRxFifoGlobalMask(INST_CANCOM1,FLEXCAN_MSG_ID_STD,0xc000000 | 0x7FF);

main.c 采用格式A。同样的ID/mask方案也可以用于格式B,这样就可以将过滤元件的数量减少到一半。

/* #####################################################
**     Filename    : main.c
**     Processor   : S32K1xx
**         Main module.
**         This module contains user's application code.
###################################################*/
// @file main.c
/* MODULE main */


/* Including necessary module. Cpu.h contains other modules needed for compiling.*/
#include "Cpu.h"
#include "clockMan1.h"

#include "dmaController1.h"

#include "pin_mux.h"

#include
#include

volatile int exit_code = 0;

/* User includes (#include below this line is not maintained by Processor Expert) */
/************************************************************************* Definitions
 *************************************************************************/

/* This example is setup to work by default with EVB. To use it with other boards,please comment the following line
*/

#define EVB

#ifdef EVB
    #define LED_PORT        PORTD
    #define GPIO_PORT       PTD
    #define PCC_INDEX       PCC_PORTD_INDEX
    #define LED0            15U
    #define LED1            16U

    #define BTN_GPIO        PTC
    #define BTN1_PIN        13U
    #define BTN2_PIN        12U
    #define BTN_PORT        PORTC
    #define BTN_PORT_IRQn   PORTC_IRQn
#else
    #define LED_PORT        PORTC
    #define GPIO_PORT       PTC
    #define PCC_INDEX       PCC_PORTC_INDEX
    #define LED0            0U
    #define LED1            1U

    #define BTN_GPIO        PTC
    #define BTN1_PIN        13U
    #define BTN2_PIN        12U
    #define BTN_PORT        PORTC
    #define BTN_PORT_IRQn   PORTC_IRQn
#endif


/* Definition of the TX and RX message buffers depending on the bus role */
#define TX_MAILBOX  (11UL)
#define TX_MSG_ID   (1UL)
#define RX_MAILBOX  (10UL)
#define RX_MSG_ID   (20UL)

/* Definition of power modes indexes, as configured in Power Manager Component
 *  Refer to the Reference Manual for details about the power modes.
 */
#define HSRUN (0u) /* High speed run      */
#define RUN   (1u) /* Run                 */
#define VLPR  (2u) /* Very low power run  */
#define STOP1 (3u) /* Stop option 1       */
#define STOP2 (4u) /* Stop option 2       */
#define VLPS  (5u) /* Very low power stop */


typedef enum
{
    LED0_CHANGE_REQUESTED = 0x00U,
    LED1_CHANGE_REQUESTED = 0x01U
} can_commands_list;

uint8_t ledRequested = (uint8_t)LED0_CHANGE_REQUESTED;
uint8_t rxMBdone=0;
uint8_t rxFIFOdone=0;
uint8_t rxFIFOcompldone=0;
/* ID Filter table */
flexcan_id_table_t filterTable[16]={};
uint16_t IDlist[16] = {0x402,0x403,0x404,0x408,0x410,0x420,0x430,0x440,0x448,0x449,0x44A,0x44B,0x44C,0x44F,0x450,0};
uint16_t IDmask[10] = {0x7FF,0x7FF,0x7FC,0x7F8,0x7F0,0x7F0,0x7F0,0x7F8,0x7FF,0x7FF};

/* Define user receive buffer */
flexcan_msgbuff_t recvBuff1, recvBuff2;

/************************************************************************* Function prototypes
 *************************************************************************/
void buttonISR(void);
void BoardInit(void);
void GPIOInit(void);
void SendCANData(uint32_t mailbox, uint32_t messageId, uint8_t * data, uint32_t len);
void flexcan0_Callback(uint8_t instance, flexcan_event_type_t eventType,
        flexcan_state_t *flexcanState);

/*************************************************************************Functions
 *************************************************************************/

/**
 * Button interrupt handler
 */
void buttonISR(void)
{
    /* Check if one of the buttons was pressed */
    uint32_t buttonsPressed = PINS_DRV_GetPortIntFlag(BTN_PORT) &
                                           ((1 << BTN1_PIN) | (1 << BTN2_PIN));
    bool sendFrame = false;

    if(buttonsPressed != 0)
    {

        /* Set FlexCAN TX value according to the button pressed */
        switch (buttonsPressed)
        {
            case (1 << BTN1_PIN):
                ledRequested = LED0_CHANGE_REQUESTED;
                sendFrame = true;
                /* Clear interrupt flag */
                PINS_DRV_ClearPinIntFlagCmd(BTN_PORT, BTN1_PIN);
                break;
            case (1 << BTN2_PIN):
                ledRequested = LED1_CHANGE_REQUESTED;
                sendFrame = true;
                /* Clear interrupt flag */
                PINS_DRV_ClearPinIntFlagCmd(BTN_PORT, BTN2_PIN);
                break;
            default:
                PINS_DRV_ClearPortIntFlagCmd(BTN_PORT);
                break;
        }

        if (sendFrame)
        {
         /* Send the information via CAN */
         SendCANData(TX_MAILBOX, TX_MSG_ID, &ledRequested, 1UL);
        }

    }
}

/*
 * @brief: Send data via CAN to the specified mailbox with the specified message id
 * @param mailbox   : Destination mailbox number
 * @param messageId : Message ID
 * @param data      : Pointer to the TX data
 * @param len       : Length of the TX data
 * @return          : None
 */
void SendCANData(uint32_t mailbox, uint32_t messageId, uint8_t * data, uint32_t len)
{
    /* Set information about the data to be sent
     *  - 1 byte in length
     *  - Standard message ID
     *  - Bit rate switch enabled to use a different bitrate for the data segment
     *  - Flexible data rate enabled
     *  - Use zeros for FD padding
     */
    flexcan_data_info_t dataInfo =
    {
            .data_length = len,
            .msg_id_type = FLEXCAN_MSG_ID_STD,
            .enable_brs  = false,
            .fd_enable   = false,
            .fd_padding  = 0U
    };

    /* Configure TX message buffer with index TX_MSG_ID and TX_MAILBOX*/
    FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, mailbox, &dataInfo, messageId);

    /* Execute send non-blocking */
    FLEXCAN_DRV_Send(INST_CANCOM1, mailbox, &dataInfo, messageId, data);
}
/*
 * @brief : Initialize clocks, pins and power modes
 */
void BoardInit(void)
{

    /* Initialize and configure clocks
     *  -   Setup system clocks, dividers
     *  -   Configure FlexCAN clock, GPIO
     *  -   see clock manager component for more details
     */
    CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                        g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
    CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

    /* Initialize Power Manager
  * -   See PowerSettings component for more info
  */
    POWER_SYS_Init(&powerConfigsArr, POWER_MANAGER_CONFIG_CNT, &powerStaticCallbacksConfigsArr, POWER_MANAGER_CALLBACK_CNT);
    /* Set power mode to HSRUN */
    POWER_SYS_SetMode(HSRUN, POWER_MANAGER_POLICY_AGREEMENT);

    /* Initialize pins
     *  -   Init FlexCAN, and GPIO pins
     *  -   See PinSettings component for more info
     */
    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
}

/*
 * @brief Function which configures the LEDs and Buttons
 */
void GPIOInit(void)
{
    /* Output direction for LEDs */
    PINS_DRV_SetPinsDirection(GPIO_PORT, (1 << LED1) | (1 << LED0));

    /* Set Output value LEDs */
    PINS_DRV_ClearPins(GPIO_PORT, 1 << LED1);

    /* Setup button pin */
    PINS_DRV_SetPinsDirection(BTN_GPIO, ~((1 << BTN1_PIN)|(1 << BTN2_PIN)));

    /* Setup button pins interrupt */
    PINS_DRV_SetPinIntSel(BTN_PORT, BTN1_PIN, PORT_INT_RISING_EDGE);
    PINS_DRV_SetPinIntSel(BTN_PORT, BTN2_PIN, PORT_INT_RISING_EDGE);

    /* Install buttons ISR */
    INT_SYS_InstallHandler(BTN_PORT_IRQn, &buttonISR, NULL);

    /* Enable buttons interrupt */
    INT_SYS_EnableIRQ(BTN_PORT_IRQn);
}

void flexcan0_Callback(uint8_t instance, flexcan_event_type_t eventType,
        flexcan_state_t *flexcanState)
{
 (void)flexcanState;
 (void)instance;

 switch(eventType)
 {
 case FLEXCAN_EVENT_RX_COMPLETE:
  {
   rxMBdone = 1;
  }
  break;
 case FLEXCAN_EVENT_RXFIFO_COMPLETE:
 {
  rxFIFOcompldone = 1;

 }
  break;
 case FLEXCAN_EVENT_DMA_COMPLETE:
  {
   rxFIFOdone = 1;
  }
  break;
 case FLEXCAN_EVENT_TX_COMPLETE:
  break;
 default:
  break;
 }
}

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
 /* Write your local variable definition here */
 uint16_t id_counter;

 /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
 #ifdef PEX_RTOS_INIT
 PEX_RTOS_INIT();                  

/* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
 #endif
 /*** End of Processor Expert internal initialization. ***/

 /* Do the initializations required for this application */
 BoardInit();
 GPIOInit();

 /*Initialize eDMA driver */
 EDMA_DRV_Init(&dmaController1_State, &dmaController1_InitConfig0, edmaChnStateArray, edmaChnConfigArray, EDMA_CONFIGURED_CHANNELS_COUNT);

 /*Initialize FlexCAN driver */
 FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
 /* Install callback function */
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, flexcan0_Callback, NULL);

 /* Set information about the data to be received */
 flexcan_data_info_t dataInfo =
 {
    .data_length = 1U,
    .msg_id_type = FLEXCAN_MSG_ID_STD,
    .enable_brs  = false,
    .fd_enable   = false,
    .fd_padding  = 0U
 };

 /* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
 FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID);

 // Fill id filter table,
#if 0
 for(id_counter=0;id_counter<16;id_counter++)
 {
  filterTable[id_counter].isRemoteFrame = false;
  filterTable[id_counter].isExtendedFrame = (id_counter % 2);
  filterTable[id_counter].id = id_counter +1 ;
 }
 /* Configure RX FIFO ID filter table elements based on filter table defined above*/
  FLEXCAN_DRV_ConfigRxFifo(INST_CANCOM1, FLEXCAN_RX_FIFO_ID_FORMAT_A, filterTable);
  /* set individual masking type */
  FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_INDIVIDUAL);
  /* first 10 filter items are masked with RXIMR0-RXIMR9 */
  for(id_counter=0;id_counter<10;id_counter++)
  FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, id_counter, 0xFFFFFFFF);
  /* rest of filter items are masked with RXFGMASK */
  FLEXCAN_DRV_SetRxFifoGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, 0xFFFFFFFF);
  /* set mask affecting MB10 */
  FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, RX_MAILBOX, 0xFFFFFFFF);
#else
 for(id_counter=0;id_counter<16;id_counter++)
 {
  filterTable[id_counter].isRemoteFrame = false;
  filterTable[id_counter].isExtendedFrame = false;
  filterTable[id_counter].id = IDlist[id_counter] ;
 }
 /* Configure RX FIFO ID filter table elements based on filter table defined above*/
 FLEXCAN_DRV_ConfigRxFifo(INST_CANCOM1, FLEXCAN_RX_FIFO_ID_FORMAT_A, filterTable);
 /* set individual masking type */
 FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_INDIVIDUAL);
 for(id_counter=0;id_counter<10;id_counter++)
  FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, id_counter, 0xC0000000|IDmask[id_counter]);
 /* rest of filter items are masked with RXFGMASK */
 FLEXCAN_DRV_SetRxFifoGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0xC0000000|0x7FF);

 /* set mask affecting MB10 */
 FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, RX_MAILBOX, 0xFFFFFFFF);

#endif

 /* Start receiving data in RX_MAILBOX. */
 FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff1);
 /* Start receiving data in RX_RXFIFO. */
 FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recvBuff2);

 while(1)
 {

  if(rxMBdone)  // if message was received into regular MB10
  {
   rxMBdone = 0;

   if(recvBuff1.msgId == RX_MSG_ID)
   {
    /* Toggle output value LED1 */
    PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));

    /* enable receiving data in RX_MAILBOX again */
    FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff1);
   }

  }
  if(rxFIFOdone)  // if message was received into RXFIFO
  {
   rxFIFOdone = 0;

   /* process data from recvBuff2 */

   /* Toggle output value LED0 */
   PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));
   /* enable receiving data in RX FIFO again */
   FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recvBuff2);


  }

 }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;) {
    if(exit_code != 0) {
      break;
    }
  }
  return exit_code;
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################
**
**     This file was created by Processor Expert 10.1 [05.21]
**     for the NXP S32K series of microcontrollers.
*/

上述是将CAN_MCR[IRQ]设置为 1 (单独的MASK) 。当然,如果内存足够使用,也可以使用如下配置,将CAN_MCR[IRQ]设置为全局的Global MASK

需要大约80个过滤器这可以使用过滤器类型B和40个过滤器完成此配置将需要所有16 MB的可用的S32K144上的RxFIFO,没有其他MB可用于其他操作。如下是 PEX 配置界面。

a2984f46c5652c489042eca186fd6a69.png

这里有一个例子,它将配置过滤器,然后初始化驱动程序。

void FlexCANInit(void)
{
flexcan_id_table_t idtable[80];
uint16_t id=2;
for (;id<0x50;id++)
{
if ((id == 0x4d) || (id == 0x4e))
{
idtable[id-2].id = 0x44f;
idtable[id-2].isExtendedFrame = false;
idtable[id-2].isRemoteFrame = false;
}
else
{
idtable[id-2].id = (0x400+id);
idtable[id-2].isExtendedFrame = false;
idtable[id-2].isRemoteFrame = false;
}
}
for(;id<80;id++)
{
idtable[id-2].id = 0x44f;
idtable[id-2].isExtendedFrame = false;
idtable[id-2].isRemoteFrame = false;
}

/*
* Initialize FlexCAN driver
* - 8 byte payload size
* - FD enabled
* - Bus clock as peripheral engine clock
*/
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1,FLEXCAN_RX_MASK_GLOBAL);
FLEXCAN_DRV_ConfigRxFifo(INST_CANCOM1,FLEXCAN_RX_FIFO_ID_FORMAT_B,&idtable[0]);
}

可以从RXFIFO中读取,将在ID 0x402-0x450(不带0x44d和0x44e)之间匹配的接收消息。

如下代码实现接受所有CAN消息(所有id没有过滤)的CAN接收器。使用当前的代码,可以传输CAN消息,但只能接收在接收消息缓冲区(MB)中指定ID的CAN消息。为什么?

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)  {}

}

使用此FlexCAN配置,无法接收任何消息。如果将一个消息ID指定到 MB中来接收,那么就可以毫无问题地接收这个消息。但是实际目的是想完全关闭过滤功能,这样就可以接收任何ID的CAN消息。

解答:

RXMGMASK (Rx Mailboxes Global Mask register)

RXIMRx (Rx Individual Mask registers)

删除红色的RXIMR寄存器的配置代码,只需将RXMGMASK设置为0x0,接收就可以按预期工作了。未修改MCR[IRMQ](默认值为0)。

清除Mask 寄存器,如果MCR[IRMQ] 被置位,则清除 RXIMR[4] - RXIMR[7];如果MCR[IRMQ]被清零,则给RXMGMASK写入0。实现不带滤波器接收的例子如下:

/*Initialize the FlexCAN module */

 FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);

/* Enable message buffer global masking */

FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_GLOBAL);

/* Set the global mask as "don't care" for each message buffer */
FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0U);

flexcan_data_info_t dataInfo =
{
.data_length = 8U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.enable_brs = false,
.fd_enable = false,
.fd_padding = 0U
};

/* Configure message buffer 0 for reception */

FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, 0U, &dataInfo, MSG_ID);

/* Start receiving data in message buffer 0 */

FLEXCAN_DRV_Receive(INST_CANCOM1, 0U, &recvBuff);

/* Wait for the reception to end */
while(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_BUSY);

MSG_ID指定编程到给定MB的ID,这里是MB0。MB ID与接收到的ID进行比较。 接收到的ID、掩码和编程的MB ID之间有位2位的对应关系。掩码表示是否将相应的传入ID位与编程的ID位进行比较。

注意标准CAN和CAN FD的区别:

4f6543ac2d8854df5f2899fea9ae4d8a.png

62b8ee5dbc73457d55480608937534b7.png

如果只有一个CAN FD控制器,可以尝试以下操作:

•对所有消息使用池。可以配置在池中读取每个消息缓冲区的频率,以便过滤在一个消息缓冲区中接收的最重要/最经常的消息,这些消息将被更频繁地读取,依此类推。可以在指定的时间间隔单独轮询每个消息缓冲区。如果消息是随机的,并且不知道时间,那么这个解决方案就不是很好。

•是否强制使用64字节有效载荷?如果减少有效载荷,那么会得到更多的MB和更多的过滤器。例如,可以配置有效负载32字节,并使用相同的ID在两组32字节中发送/接收一条64字节消息,然后在应用程序中重新组合该消息。这将使消息缓冲区和筛选过滤器的数量加倍。如果配置较低的有效负载,则可以获得更多MB和更多筛选过滤器。

欢迎关注:

df715e35d743e8ec307d3a424bd29c0d.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/144516
推荐阅读
相关标签
  

闽ICP备14008679号