打印

打着雨伞请教(之3),关于GPIO口的设置问题

[复制链接]
2125|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
程序匠人|  楼主 | 2009-1-23 16:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

打着雨伞请教(之3),关于GPIO口在设置为输入状态下是否需要设置速度的问题 

以下代码是从万历板载DEMO例程中挖出来的(请注意红色部分): 
/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configures the different GPIO ports.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure PC.00 (ADC Channel10) as analog input -------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  // for LCD display -- segment
  /* Configure PE.00 -- PE.15 as Output push-pull : SEG0~15 */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  // for LCD display -- com 
  /* Configure PC.08 -- PC.11 as Output push-pull  : COM1~4 */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  // for 4 LEDs
  /* Configure PC.04 -- PC.07 as Output push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  // for KEY2 & KEY3 (PD.3/4) and JoyStick(PD.11~15)
   /* Configure PD.03, PD.04, PD.11 -- PD.15 as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |
      GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOD, &GPIO_InitStructure);  
  
  // for usb.cs
    /* PD.08 used as USB pull-up --> EK-STM32F */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  // for JoyStick
  /* Configure the JoyStick IOs */
  /* Key (up + down + left + right */
  GPIO_InitStructure.GPIO_Pin = JOY_UP | JOY_DOWN |JOY_LEFT | JOY_RIGHT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

  GPIO_Init(GPIOD, &GPIO_InitStructure);
}


从《STM32系列 RAM Cortex-M3微控制器 原理与实践》一书上(第110,表3.11、表3.12)得知,速率仅仅是针对输出模式而言的,而对于输入模式来说,没速率设置一说。
匠人的问题:为什么例程中在把“JOY_UP | JOY_DOWN |JOY_LEFT | JOY_RIGHT”这四个IO口设置为输入上拉模式时,还要设置速率?到底是例程错了,还是书错了,还是匠人错了?
 
沙发
computer00| | 2009-1-23 16:28 | 只看该作者

多一个操作没影响吧...

使用特权

评论回复
板凳
程序匠人|  楼主 | 2009-1-23 16:33 | 只看该作者

应该没有影响,否则就不会当作demo发布出来了。



匠人关心的不是 是否多一个无效的操作,而是,该操作是否是必须的?

使用特权

评论回复
地板
程序匠人|  楼主 | 2009-1-23 16:33 | 只看该作者

圈圈不回家吗?

使用特权

评论回复
5
computer00| | 2009-1-23 16:38 | 只看该作者

明天就回,哈哈~~~

使用特权

评论回复
6
ijk| | 2009-1-23 16:49 | 只看该作者

应该是多此一举

  就公开的资料来看(未公开的资料没看过),这(输入模式下设置速率)应该是多此一举。

使用特权

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

本版积分规则

734

主题

11156

帖子

675

粉丝