问答

汇集网友智慧,解决技术难题

21ic问答首页 - GD32F103C8T6,使用ST标准库,CAN初始化失败

gd32F103 国产芯片 ST 失败 CAN 使用

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

fw198763112025-01-14
本帖最后由 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;=====================卡在这个位置  }
请教各位,有遇到过吗?麻烦指导下,谢谢大家!














回答 +关注 0
156人浏览 0人回答问题 分享 举报
0 个回答

您需要登录后才可以回复 登录 | 注册