STM32F405RG CAN1 TX interrupt works well, but RX0 and RX1 cannot be triigered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-19 7:14 PM
When I use the STM32F405RG to send and receive CAN message, it can send message successfully and trigger the tx interrupt, but it cannot trigger the RX0 and RX1 interrupts, the code was generated with STM32CUBEIDE. The relative code is as follows:
1 .filter code:
void vApp_CAN_Filter_Init(CAN_FilterTypeDef *pFilter, uint32_t IdHigh,
uint32_t IdLow, uint32_t MaskIdHigh, uint32_t MaskIdLow,
uint32_t FIFOAssignment, uint32_t Bank, uint32_t Mode, uint32_t Scale,
uint32_t Activation, uint32_t SlaveStartFilterBank) {
pFilter->FilterIdHigh = 0;
pFilter->FilterIdLow = 0;
pFilter->FilterMaskIdHigh = 0;
pFilter->FilterMaskIdLow = 0;
pFilter->FilterFIFOAssignment = CAN_FILTER_FIFO0;
pFilter->FilterBank = 0;
pFilter->FilterMode = CAN_FILTERMODE_IDMASK;
pFilter->FilterScale = CAN_FILTERSCALE_32BIT;
pFilter->FilterActivation = ENABLE;
pFilter->SlaveStartFilterBank = 0;
}
vApp_CAN_Filter_Init(pFilter, IdHigh, IdLow, MaskIdHigh, MaskIdLow,
FIFOAssignment, Bank, Mode, Scale, Activation,
SlaveStartFilterBank);
2 . Start code and interrupt enable
/*-3- start CAN ---------------------------------------------------*/
while (HAL_CAN_Start(&hcan1) != HAL_OK) {
printf("\nCAN_Start Failed!!");
HAL_Delay(100);
}
printf("\nCAN_Start Success!!");
/*-4- Enable Interrupts ----------------------------------------------*/
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO1_MSG_PENDING);
}
3 . Call backs:
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
uint8_t aRxData[8], i;
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &hCAN1_RxHeader, aRxData)
== HAL_OK) {
printf("\nGet Rx Message Success!!\nData:");
for (i = 0; i < 8; i++)
printf("%d", aRxData[i]);
}
}
- Labels:
-
CAN
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-19 7:16 PM
The code posted not show the tx interrupt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-19 7:21 PM
The library is F4 V1.25.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-21 12:31 AM
After I switched the CANALYST (kind of CAN analyzer) from this board to anther board and then switch​ed back, it worked.
It seemed that even if the CANALYST could receive the message from the STM32, it cannot send message to the stm32, the line was the main cause to this problem.
