打印
[STM32F1]

GD32F103C8T6,使用ST标准库,CAN初始化失败

[复制链接]
164|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
fw19876311|  楼主 | 2025-1-14 14:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 fw19876311 于 2025-1-14 17:01 编辑

STM32F103C8T6正常运行的代码,直接平替GD32F103C8,CAN部分初始化异常,一直返回失败
uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct){
uint8_t InitStatus = CAN_InitStatus_Failed;

uint32_t wait_ack = 0x00000000;
  /* Check theparameters*/assert_param(IS_CAN_ALL_PERIPH(CANx));assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
assert_param(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
assert_param(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
assert_param(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
assert_param(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
assert_param(IS_CAN_PRESCALER(CAN_InitStruct->CAN_Prescaler));  /* Exit from sleep mode */
CANx->MCR &= (~(uint32_t)CAN_MCR_SLEEP);  /* Request initialisation */
CANx->MCR |= CAN_MCR_INRQ ;  /* Wait the acknowledge */
while (((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))  {    wait_ack++;  }  /* Check acknowledge */
if ((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
{    InitStatus = CAN_InitStatus_Failed;=====================卡在这个位置  }
请教各位,有遇到过吗?麻烦指导下,谢谢大家!














使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

4

帖子

0

粉丝