cancel
Showing results for 
Search instead for 
Did you mean: 

I operated according to this instruction, but CAN failed to wake up. May I ask what is the reason?

hzhao.5
Associate

/**

 * @brief Enters the low power mode.

 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.

 * @retval status: CAN_Sleep_Ok if sleep entered, CAN_Sleep_Failed in an 

 *        other case.

 */

uint8_t CAN_Sleep(CAN_TypeDef* CANx)

{

 uint8_t sleepstatus = CAN_Sleep_Failed;

  

 /* Check the parameters */

 assert_param(IS_CAN_ALL_PERIPH(CANx));

   

 /* Request Sleep mode */

  CANx->MCR = (((CANx->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);

  

 /* Sleep mode status */

 if ((CANx->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) == CAN_MSR_SLAK)

 {

  /* Sleep mode not entered */

  sleepstatus = CAN_Sleep_Ok;

 }

 /* return sleep mode status */

  return (uint8_t)sleepstatus;

}

/**

 * @brief Wakes the CAN up.

 * @param CANx:  where x can be 1 or 2 to to select the CAN peripheral.

 * @retval status: CAN_WakeUp_Ok if sleep mode left, CAN_WakeUp_Failed in an 

 *         other case.

 */

uint8_t CAN_WakeUp(CAN_TypeDef* CANx)

{

 uint32_t wait_slak = SLAK_TIMEOUT;

 uint8_t wakeupstatus = CAN_WakeUp_Failed;

  

 /* Check the parameters */

 assert_param(IS_CAN_ALL_PERIPH(CANx));

   

 /* Wake up request */

 CANx->MCR &= ~(uint32_t)CAN_MCR_SLEEP;

   

 /* Sleep mode status */

 while(((CANx->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)&&(wait_slak!=0x00))

 {

  wait_slak--;

 }

 if((CANx->MSR & CAN_MSR_SLAK) != CAN_MSR_SLAK)

 {

  /* wake up done : Sleep mode exited */

  wakeupstatus = CAN_WakeUp_Ok;

 }

 /* return wakeup status */

 return (uint8_t)wakeupstatus;

}

1 REPLY 1
GigaGigue
Associate

Do you have a can transceiver connected? If not, that is the cause. You can also connect rx to pull-up if you don't have one near you, but it won't create miracle.