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
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章