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