Home > other >  STM32 receive double FIFO use of CAN bus
STM32 receive double FIFO use of CAN bus

Time:09-21

HAL generated by cubemx library, the CAN module configuration is as follows:
 CAN_HandleTypeDef hcan; 
CanTxMsgTypeDef TxMessage;
CanRxMsgTypeDef RxMessage;
/* CAN init function */
Void MX_CAN_Init (void)
{

Hcan. Instance=CAN;
Hcan. PTxMsg=& amp; TxMessage;
Hcan. PRxMsg=& amp; RxMessage;
//250 k
Hcan. Init. Prescaler=12;
Hcan. Init. Mode=CAN_MODE_NORMAL;
Hcan. Init. SJW=CAN_SJW_1TQ;
Hcan. Init. BS1=CAN_BS1_7TQ;
Hcan. Init. BS2=CAN_BS2_8TQ;
Hcan. Init. TTCM=DISABLE;
Hcan. Init. ABOM=ENABLE;
Hcan. Init. AWUM=DISABLE;
Hcan. Init. NART=DISABLE;
Hcan. Init. RFLM=DISABLE;
Hcan. Init. TXFP=DISABLE;
If (HAL_CAN_Init (& amp; Hcan)!=HAL_OK)
{
Error_Handler ();
}

CAN_FilterConfTypeDef sFilterConfig;
///* # # - 2 - Configure the CAN Filter # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # */
//sFilterConfig. FilterNumber=0;
//sFilterConfig. FilterMode=CAN_FILTERMODE_IDMASK;
//sFilterConfig. FilterScale=CAN_FILTERSCALE_32BIT;
//sFilterConfig. FilterIdHigh=0 x0000;
//sFilterConfig. FilterIdLow=0 x0000;
//sFilterConfig. FilterMaskIdHigh=0 x0000;
//sFilterConfig. FilterMaskIdLow=0 x0000;
//sFilterConfig. FilterFIFOAssignment=CAN_FILTER_FIFO0;
//sFilterConfig. FilterActivation=ENABLE;
//sFilterConfig. BankNumber=14;
//if (HAL_CAN_ConfigFilter (& amp; Hcan, & amp; SFilterConfig)!=HAL_OK)
//{
///* Filter configuration Error */
//Error_Handler ();
//}
//HAL_CAN_Receive_IT (& amp; Hcan CAN_FIFO0);//enabled CAN receive interrupt

/* # # 2 - Configure the CAN Filter # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # */
SFilterConfig. FilterNumber=1;
SFilterConfig. FilterMode=CAN_FILTERMODE_IDMASK;
SFilterConfig. FilterScale=CAN_FILTERSCALE_32BIT;
SFilterConfig. FilterIdHigh=0 x0000;
SFilterConfig. FilterIdLow=0 x0000;
SFilterConfig. FilterMaskIdHigh=0 x0000;
SFilterConfig. FilterMaskIdLow=0 x0000;
SFilterConfig. FilterFIFOAssignment=CAN_FILTER_FIFO1;
SFilterConfig. FilterActivation=ENABLE;
SFilterConfig. BankNumber=14;

If (HAL_CAN_ConfigFilter (& amp; Hcan, & amp; SFilterConfig)!=HAL_OK)
{
/* Filter configuration Error */
Error_Handler ();
}
HAL_CAN_Receive_IT (& amp; Hcan CAN_FIFO1);//enabled CAN receive interrupt
}

The part of the code above commented out CAN_FIFO0, can be normal to receive data (into CAN_FIFO0 receiving interrupt); CAN_FIFO1 conversely, commented that part is also can be normal to receive data (into CAN_FIFO1 receiving interrupt), but if both configuration (not commented out), has been only enter CAN_FIFO0 receiving interrupt, I want to the effect of alternating trigger, can be the same as USB double-buffering?

CodePudding user response:

After every time can accept to the specified buffer

CodePudding user response:

CUBEMX configuration of time how to configure FIFO wow

CodePudding user response:

The building Lord problem can be solved by reference to the: https://blog.csdn.net/xiaoyaofriend/article/details/104138618
  • Related