STM32 GPIO

#include "stm32f10x.h"

void APClkInit(void);
void GPIO_Init(void);	//32位的处理器 int 是4个字节的
#define BIT2      1 << 2;
#define GPIOA_EN  BIT2


int main(void)
{
	APClkInit();
	GPIO_Init();
	GPIOA->BSRR = 1<<4;	  // 置位PA.4
	while(1); 
}

/*HSI high speed internal clk 内部高速时钟
  HSE high speed external clk 外部高速时钟
  LSE low  speed external clk 32768 RTC
  LSI low  speed internal clk   40KHz || CLK >> 30KHz && CLK << 60KHz
  内部时钟可能和温度有关
  单片机复位的时候 是用的HSI 
  typedef struct
{
  __IO uint32_t CR;	  		//control register
  __IO uint32_t CFGR; 		//config
  __IO uint32_t CIR;  		//interrup
  __IO uint32_t APB2RSTR;   // APB2 reset
  __IO uint32_t APB1RSTR;   // APB1 reset
  __IO uint32_t AHBENR;	    //
  __IO uint32_t APB2ENR;
  __IO uint32_t APB1ENR;    // AHB APB1 APB2
  __IO uint32_t BDCR;
  __IO uint32_t CSR;        // state
#ifdef STM32F10X_CL  
  __IO uint32_t AHBRSTR;
  __IO uint32_t CFGR2;
#endif /// STM32F10X_CL/ 
} RCC_TypeDef;

#define PERIPH_BASE           ((uint32_t)0x40000000) //!< SRAM base address in the bit-band region 
#define AHBPERIPH_BASE        (PERIPH_BASE + 0x20000)
#define RCC_BASE              (AHBPERIPH_BASE + 0x1000)
#define RCC                 ((RCC_TypeDef *) RCC_BASE)
*/
void APClkInit(void)
{
	 RCC->APB2ENR = GPIOA_EN;
}

/*typedef struct
{
  __IO uint32_t CRL;
  __IO uint32_t CRH; // 配置
  __IO uint32_t IDR; // 
  __IO uint32_t ODR; // 
  __IO uint32_t BSRR;// 清除和复位
  __IO uint32_t BRR; //	清除
  __IO uint32_t LCKR;
} GPIO_TypeDef;
IO 有8种模式

推挽输出 
开漏输出
上拉输入
下拉输入

复用推挽
复用开漏
模拟输入
浮动输入

响应速度 2M 10M 50M这个不是IO的速度是指的IO响应的速度,算STM32 功耗设计吧
*/

void GPIO_Init(void)
{
    GPIOA->CRL = 0x01 << 16;	// PA.4	 10M  OUTPP
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值