2022-09-30 02:45 PM
I am working on power management and I put MCU in sleep mode (no low-power), but it doesn't wake up when it receives a CAN frame, it stays in sleep mode. I would like any CAN frame to wake up the MCU.
To switch to sleep mode I use :
HAL_SuspendTick();
HAL_TIM_Base_Stop(&htim1);
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_TIM_Base_Start(&htim1);
HAL_ResumeTick();
tick_sleep = HAL_GetTick();
Can Bus configuration:
void MX_CAN_Init(void)
{
/* USER CODE BEGIN CAN_Init 0 */
/* USER CODE END CAN_Init 0 */
/* USER CODE BEGIN CAN_Init 1 */
/* USER CODE END CAN_Init 1 */
hcan.Instance = CAN1;
hcan.Init.Prescaler = 6;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_2TQ;
hcan.Init.TimeSeg2 = CAN_BS2_1TQ;
hcan.Init.TimeTriggeredMode = DISABLE;
hcan.Init.AutoBusOff = ENABLE;
hcan.Init.AutoWakeUp = ENABLE;
hcan.Init.AutoRetransmission = ENABLE;
hcan.Init.ReceiveFifoLocked = DISABLE;
hcan.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN_Init 2 */
HAL_CAN_Start(&hcan);
CAN_FilterTypeDef sFilterConfig;
sFilterConfig.FilterIdHigh = 0xFFFF;
sFilterConfig.FilterIdLow = 0xFFFF;
sFilterConfig.FilterMaskIdHigh = 0;
sFilterConfig.FilterMaskIdLow = 0;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterBank = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 0;
HAL_CAN_ConfigFilter(&hcan,&sFilterConfig);
/* USER CODE END CAN_Init 2 */
}
In my code I have configure CAN Rx as interrupt.
Solved! Go to Solution.
2022-10-01 12:45 PM
Ok I find solution. I forgot add
HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
2022-10-01 12:45 PM
Ok I find solution. I forgot add
HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);