can

stm32f103使用cube配置CAN通信后,调用HAL_CAN_AddTxMessage死在硬件错误

本人相关配置在stm32f105和stm32f427中均正常使用,但是在stm32f103c8t6中,就会出现上述问题。

/**

 * @description: CAN³õʼ»¯

 * @param {hcan2µÄµØÖ·} 

 * @return: void

 * @note: Â˲¨

 */

void CAN_Init(CAN_HandleTypeDef *hcanX)

{

    uint32_t FilterBank, FilterFIFO;

    CAN_FilterTypeDef sFilterConfig;

    if(hcanX == &hcan)

    {

        FilterBank = 0;

        FilterFIFO = CAN_RX_FIFO0;

    }

//    else if(hcan == &hcan2)

//    {

//        FilterBank = 14;

//        FilterFIFO = CAN_RX_FIFO1;

//    }

    else

    {

        return;

    }

    sFilterConfig.FilterBank = FilterBank;

    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

    sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

    sFilterConfig.FilterIdHigh = 0x0000;

    sFilterConfig.FilterIdLow = 0x0000;

    sFilterConfig.FilterMaskIdHigh = 0x0000;

    sFilterConfig.FilterMaskIdLow = 0x0000;

    sFilterConfig.FilterFIFOAssignment = FilterFIFO;

    sFilterConfig.FilterActivation = ENABLE;

    sFilterConfig.SlaveStartFilterBank = 7;

    HAL_CAN_ConfigFilter(hcanX, &sFilterConfig);

    HAL_CAN_Start(hcanX);

}


/**

 * @description: ʹÄÜCAN½ÓÊյȴýÖжÏ

 * @param {hcanµÄµØÖ·} 

 * @return: void

 * @note: canµÄÖжÏʹÄÜ

 */

void CAN_Recieve(CAN_HandleTypeDef *hcanX)              

{

uint32_t ActiveITs;

  if(hcanX == &hcan)

  {

     ActiveITs = CAN_IT_RX_FIFO0_MSG_PENDING;

  }

//  else if(hcan == &hcan2)

//  {

//     ActiveITs = CAN_IT_RX_FIFO1_MSG_PENDING;

//  }

  else

  {

     return;

  }

  HAL_CAN_ActivateNotification(hcanX, ActiveITs);             

}

调用这两个函数进行初始化

求问大家stm32f103的CAN配置和使用有什么坑啊,调了一天了,都没出来

已邀请:

public_rtos

赞同来自:

用CUBE软件生成吧,基本都是没什么问题的。要不然很复杂的

要回复问题请先登录注册