stm32 直接讀寫寄存器代碼風格總結(jié)
根據(jù)memory mapping 直接寫寄存器代碼風格:
本文引用地址:http://m.butianyuan.cn/article/201611/317633.htm#define GPIOA_BASE1 (uint32_t)0x40010800#define GPIOA_CRH ((uint32_t*)(GPIOA_BASE1+0x04))轉(zhuǎn)換為指針之后,直接讀寫:
*GPIOA_CRH=0x000004B0;//A端口//復用推挽輸出
結(jié)構(gòu)體指針解決連續(xù)多個寄存器讀寫設(shè)置:
#define Usart1_BASE 0x40013800typedef struct{__IO uint32_t SR;__IO uint32_t DR;__IO uint32_t BRR;__IO uint32_t CR1;__IO uint32_t CR2;__IO uint32_t CR3;__IO uint32_t GTPR;}Usart1_typedef;#define Usart1 ((Usart1_typedef*)Usart1_BASE)
Usart1->CR1=0x0000000C;
評論