【求助】stm32f042的CAN为何初始化失败?

[复制链接]
2194|5
 楼主| cainiao518 发表于 2018-12-13 15:34 | 显示全部楼层 |阅读模式
本帖最后由 cainiao518 于 2018-12-14 09:18 编辑
  1. static void CAN_GPIO_Configuration(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_InitStructure;
  4.         
  5.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);                                                                                                                        
  6.         
  7.         /* CAN1 Periph clock enable */
  8.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
  9.         
  10.         GPIO_PinAFConfig(GPIOA,GPIO_PinSource11, GPIO_AF_4);//RX
  11.     GPIO_PinAFConfig(GPIOA,GPIO_PinSource12, GPIO_AF_4);//TX
  12.         
  13.         /* Configure CAN pin: RX */                                                                                       //        
  14.         GPIO_InitStructure.GPIO_Pin    = CAN_RX;
  15.         GPIO_InitStructure.GPIO_Mode   = GPIO_Mode_AF;
  16.         GPIO_InitStructure.GPIO_PuPd   = GPIO_PuPd_UP;
  17.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  18.         
  19.         /* Configure CAN pin: TX */                                                                                       //
  20.         GPIO_InitStructure.GPIO_Pin    = CAN_TX;
  21.         GPIO_InitStructure.GPIO_Mode   = GPIO_Mode_AF;
  22.         GPIO_InitStructure.GPIO_OType  = GPIO_OType_PP;
  23.         GPIO_InitStructure.GPIO_Speed  = GPIO_Speed_50MHz;
  24.         GPIO_InitStructure.GPIO_PuPd   = GPIO_PuPd_NOPULL;
  25.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  26. }


https://bbs.21ic.com/icview-2602424-1-1.html
 楼主| cainiao518 发表于 2018-12-14 09:19 | 显示全部楼层
或者有例程也行
dirtwillfly 发表于 2018-12-14 21:51 | 显示全部楼层
官网有提供基于hal库的例程的,建议楼主参考一下阿
 楼主| cainiao518 发表于 2018-12-15 10:16 | 显示全部楼层
dirtwillfly 发表于 2018-12-14 21:51
官网有提供基于hal库的例程的,建议楼主参考一下阿

有没链接呢
零三翟邢止胃 发表于 2019-3-27 10:49 | 显示全部楼层

官网有提供基于hal库的例程的
airwill 发表于 2019-3-27 19:23 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

135

主题

1431

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部