cancel
Showing results for 
Search instead for 
Did you mean: 

Wake up MCU by CANbus interruptions from sleep mode (STM32F1)

MSkor.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
MSkor.1
Associate II

Ok I find solution. I forgot add

HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);

View solution in original post

1 REPLY 1
MSkor.1
Associate II

Ok I find solution. I forgot add

HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);