打印

求助:STM32F的GPIO函数GPIO_Init,请大家帮忙

[复制链接]
3411|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wet999|  楼主 | 2008-4-1 10:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  在GPIO.C函数中,有一个函数GPIO_Init,其中有几句看不懂:
  ......
  if(currentpin==pos)
   pos=pinpos<<2;
   pinmask=((u32)0x0F)<<pos;
   tmpreg&=~pinmask;
   tmpreg|=(currentmode<<pos);
  ......
   看了几天也没看懂,请大家帮助分析一下.

   
沙发
wet999|  楼主 | 2008-4-1 10:37 | 只看该作者

还是看不懂

 pos=pinpos<<2 ;左移2位,什么意思?为什么要左移2位?能说详细点吗?
 还有下面的0xOF左移POS位,什么意思?pinmask代表什么?

使用特权

评论回复
板凳
香水城| | 2008-4-1 11:18 | 只看该作者

在STM32固件库的源程序中有详细的注解

这一段是设置GPIO CRL寄存器,请参考STM32技术参考手册中的相关部分。


/*---------------------------- GPIO CRL Configuration ------------------------*/
  /* Configure the eight low port pins */
  if (((u32)GPIO_InitStruct->GPIO_Pin & ((u32)0x00FF)) != 0x00)
  {
    tmpreg = GPIOx->CRL;

    for (pinpos = 0x00; pinpos < 0x08; pinpos++)
    {
      pos = ((u32)0x01) << pinpos;
      /* Get the port pins position */
      currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;

      if (currentpin == pos)
      {
        pos = pinpos << 2;
        /* Clear the corresponding low control register bits */
        pinmask = ((u32)0x0F) << pos;
        tmpreg &= ~pinmask;

        /* Write the mode configuration in the corresponding bits */
        tmpreg |= (currentmode << pos);

        /* Reset the corresponding ODR bit */
        if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
        {
          GPIOx->BRR = (((u32)0x01) << pinpos);
        }
        /* Set the corresponding ODR bit */
        if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
        {
          GPIOx->BSRR = (((u32)0x01) << pinpos);
        }
      }
    }
    GPIOx->CRL = tmpreg;
    tmpreg = 0;
  }

使用特权

评论回复
地板
jessemok| | 2008-4-1 16:46 | 只看该作者

看相关寄存器说明

和操作的寄存器说明对照着看就能看懂了,要是再看不懂,估计没有能再回答你了。

使用特权

评论回复
5
chunfeng12| | 2008-4-1 17:41 | 只看该作者

呵呵

C语言基本的东东啊

使用特权

评论回复
6
americ| | 2008-4-1 18:03 | 只看该作者

ARM 寄存器 比 51 寄存器 功能复杂一点

针对某些应用,更方便了

使用特权

评论回复
7
short_long| | 2008-4-2 20:38 | 只看该作者

IO

看来楼主要加油了,呵呵

使用特权

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

本版积分规则

15

主题

37

帖子

0

粉丝