2019-06-06 07:33 AM
I'm working on an STM32L431 and I never be call on HAL_CAN_RxFifo0MsgPendingCallback. I have set a break point in this function but the debugger never stop on it.
In my program:
void MX_CAN1_Init(void)
{
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 5;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = ENABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
}
(HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING)
void canDriver_init( ){
// First of all enable the CAN
HAL_GPIO_WritePin(EN_CAN_GPIO_Port, EN_CAN_Pin, GPIO_PIN_RESET);
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterIdHigh = 0x320 << 5;
sFilterConfig.FilterIdLow = 0;
sFilterConfig.FilterMaskIdHigh = 0xFFF << 5;
sFilterConfig.FilterMaskIdLow = 0;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterBank = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterActivation = DISABLE;
sFilterConfig.SlaveStartFilterBank = 14;
if (HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
/* Start the CAN peripheral */
if (HAL_CAN_Start(&hcan1) != HAL_OK)
{
/* Start Error */
Error_Handler();
}
/* Activate CAN RX notification */
if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
/* Notification Error */
Error_Handler();
}
TxHeader.StdId = 0x320; /* Specify the remote CAN node address */
TxHeader.ExtId = 0x01; /* Not used here */
TxHeader.RTR = CAN_RTR_DATA; /* Data Frame type (Data or Commands) */
TxHeader.IDE = CAN_ID_STD; /* Standard frame but not Extended */
TxHeader.DLC = 2; /* Number of data size in bytes (from 0 to 8)*/
TxHeader.TransmitGlobalTime = DISABLE;
}
My test:
=> I already receive it in my CAN analyzer
=> but those frame never be received by the STM32 (I already see the hardware signal on the medium using an oscilloscope)
Thanks for your help
Regards
Solved! Go to Solution.
2019-06-25 12:33 AM
I slove the issue by activate the filtre:
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterBank = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 14;
If the FilterActivation is not ENABLE it was impossible to receive CAN frame.
2019-06-07 12:01 AM
The code looks fine. I would first try fully opening the can filter to let everything through, see if anything triggers the interrupt.
2019-06-07 02:48 AM
Hello @Community member ,
First of all, Thanks for your help.
In my understanding, the filter is already disable and not used in my config because I have set:
sFilterConfig.FilterActivation = DISABLE;
is it true ?
2019-06-13 06:30 AM
Anyone have an idea to help me ?
Thanks
2019-06-25 12:33 AM
I slove the issue by activate the filtre:
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterBank = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 14;
If the FilterActivation is not ENABLE it was impossible to receive CAN frame.