当前位置:   article > 正文

STM32F407学习笔记二(GPIO)_gpiod->moder

gpiod->moder

从上文可以看到,在系统启动过程中会对系统时钟进行一次配置,有了时钟源以后,我们来看简单的GPIO配置:对于GPIO,使用寄存器进行配置时:我们先来看一个例子:


  1. #include <stm32f4xx.h>
  2. uint32_t Gb_TimingDelay;
  3. void Delay(uint32_t nTime);
  4. void main()
  5. {
  6. SysTick_Config(SystemCoreClock/1000);//1ms based time
  7. RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; //ENABLE GPIOD
  8. RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; //ENABLE SYSCFG
  9. GPIOD->MODER &= 0x00FFFFFF; //set direction
  10. GPIOD->MODER |= 0x55000000;
  11. GPIOD->OTYPER &= 0xFFFF0FFF; //set the way of output:31-16:observed 15-0: 1: output push-pull 0: output open-drain
  12. GPIOD->OSPEEDR &= 0X00FFFFFF; //speed
  13. GPIOD->OSPEEDR |= 0XFF000000;
  14. SYSCFG->CMPCR =0X00000001; //speed CMR
  15. GPIOD->PUPDR= 0X00FFFFFF; //pull-up or pull-down
  16. GPIOD->BSRRH= 0XF000; //clear or set
  17. while(1)
  18. {
  19. GPIOD->BSRRH = 0XF000;
  20. GPIOD->BSRRL = 0X1000;
  21. Delay(100);
  22. GPIOD->BSRRH = 0XF000;
  23. GPIOD->BSRRL = 0X1000<<1;
  24. Delay(100);
  25. GPIOD->BSRRH = 0XF000;
  26. GPIOD->BSRRL = 0X1000<<2;
  27. Delay(100);
  28. GPIOD->BSRRH = 0XF000;
  29. GPIOD->BSRRL = 0X1000<<3;
  30. Delay(100);
  31. }
  32. }
  33. void Delay(uint32_t nTime) //Delay
  34. {
  35. Gb_TimingDelay = nTime;
  36. while(Gb_TimingDelay!=0);
  37. }
  38. void SysTick_Handle() //interrupt handle
  39. {
  40. if(Gb_TimingDelay!=0)
  41. {
  42. Gb_TimingDelay--;
  43. }
}
首先调用了
SysTick_Config,我们来看看这个函数:
  1. __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
  2. {
  3.   if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk)  return (1);      /* Reload value impossible */
  4.   SysTick->LOAD  = ticks - 1;                                  /* set reload register */
  5.   NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Systick Interrupt */
  6.   SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
  7.   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
  8.                    SysTick_CTRL_TICKINT_Msk   |
  9.                    SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
  10.   return (0);                                                  /* Function successful */
  11. }

可以看到这是对时钟中断进行配置,

每隔168000000/1000 *1/168000000=1ms产生一次中断。

我们重点看GPIO寄存器·:

1.GPIO端口模式寄存器GPIOx_MODER





2.GPIO端口输出类型寄存器GPIOx_OTYPER




3.GPIO端口输出速度控制器GPIOx_OSPEEDR



4.GPIO端口上拉下拉寄存器GPIOx_PUPDR



5.GPIO端口置位复位寄存器GPIOx_BSRR









声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/281097
推荐阅读
相关标签
  

闽ICP备14008679号