2023-04-04 05:30 AM
Hello,
when I try to receive a CAN-Frame it is not received by the Microcontroller, it is within the range, I have no idea what the issue is.
Thanks to everybody in advance, Best Regards, Seppel
void FDCAN_Config(FDCAN_HandleTypeDef *pHfdcan)
{
pHandleToFdCan = pHfdcan;
/* Configure Rx filter */
sFilterConfig.IdType = FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_RANGE;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = 0x700;
sFilterConfig.FilterID2 = 0x7FF;
if (HAL_FDCAN_ConfigFilter(pHandleToFdCan, &sFilterConfig) != HAL_OK)
{
Error_Handler();
}
/* Configure global filter:
Filter all remote frames with STD and EXT ID
Reject non matching frames with STD ID and EXT ID */
if (HAL_FDCAN_ConfigGlobalFilter(pHandleToFdCan, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT) != HAL_OK)
{
Error_Handler();
}
/* Start the FDCAN module */
if (HAL_FDCAN_Start(pHandleToFdCan) != HAL_OK)
{
Error_Handler();
}
if (HAL_FDCAN_ActivateNotification(pHandleToFdCan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
{
Error_Handler();
}
}
P.S. TX works perfectly fine, as you can see it Ack's the 0x701 Frame that was received.
2023-04-04 09:13 AM
Yes, the RX callback is working fine.
Here's my setup. In this case for an H7 MCU. Bitrate is 500kB
static void MX_FDCAN1_Init(void)
{
/* USER CODE BEGIN FDCAN1_Init 0 */
/* USER CODE END FDCAN1_Init 0 */
/* USER CODE BEGIN FDCAN1_Init 1 */
/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 4;
hfdcan1.Init.NominalSyncJumpWidth = 8;
hfdcan1.Init.NominalTimeSeg1 = 12;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 10;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 13;
hfdcan1.Init.DataTimeSeg2 = 2;
hfdcan1.Init.MessageRAMOffset = 0;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.RxFifo0ElmtsNbr = 1;
hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxFifo1ElmtsNbr = 1;
hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxBuffersNbr = 10;
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.TxEventsNbr = 10;
hfdcan1.Init.TxBuffersNbr = 2;
hfdcan1.Init.TxFifoQueueElmtsNbr = 2;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN1_Init 2 */
/* USER CODE END FDCAN1_Init 2 */
}
After calling the above init in my main, I call these two:
if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
if(HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
{
Error_Handler();
}
When any CAN message is sent by a node other than the ST MCU, this callback is triggered:
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
{
Error_Handler();
}
if (RxHeader.Identifier==0x250) PC13state++;
}
2023-04-04 09:31 AM
And in the IRQ handler I check its source, set some flags which I check later in main, then call the HAL IRQ handler to reset register flags.
/**
* @brief This function handles FDCAN1 interrupt 0.
*/
void FDCAN1_IT0_IRQHandler(void)
{
/* get PTP time */
ETH_PTPTime_GetTime(&sTimeCanRx);
if( FDCAN1->IR & FDCAN_IR_RF0N )
{
sCan1RxFifo0.RxdIrq = 1;
sCan1RxFifo0.sTimeRx.seconds = sTimeCanRx.seconds;
sCan1RxFifo0.sTimeRx.nanosec = sTimeCanRx.nanosec;
}
if( FDCAN1->IR & FDCAN_IR_RF1N )
{
sCan1RxFifo1.RxdIrq = 1;
sCan1RxFifo1.sTimeRx.seconds = sTimeCanRx.seconds;
sCan1RxFifo1.sTimeRx.nanosec = sTimeCanRx.nanosec;
}
if( FDCAN1->IR & FDCAN_IR_DRX )
{
sCan1RxBuffer.RxdIrq = 1;
sCan1RxBuffer.sTimeRx.seconds = sTimeCanRx.seconds;
sCan1RxBuffer.sTimeRx.nanosec = sTimeCanRx.nanosec;
}
HAL_FDCAN_IRQHandler(&hCan1);
}
2023-04-12 02:03 AM
Hello,
the issue is resolved:
Issue visible in the Code:
hfdcan2.Init.StdFiltersNbr = 0;
Solution, change the Config in the Stm32CubeIde, set the number of filters to 1, the generated code will be:
hfdcan2.Init.StdFiltersNbr = 1;
Thanks a lot to everybody supporting the case.
Best Regards, Seppel
P.S. It is so obvious that if you use a filter the number of filters should not be zero. But as always: "You know afterwards, what you could have known in advance". 8)