操作寄存器有
#1.GPIO 端口模式寄存器 (GPIOx_MODER) (x = A..I)
#2.GPIO 端口输出类型寄存器 (GPIOx_OTYPER) (x = A..I)
#3.GPIO 端口输出速度寄存器 (GPIOx_OSPEEDR) (x = A..I)
#4.GPIO 端口上拉/下拉寄存器 (GPIOx_PUPDR) (x = A..I)
#5.GPIO 端口输入数据寄存器 (GPIOx_IDR) (x = A..I)
#6.GPIO 端口输出数据寄存器 (GPIOx_ODR) (x = A..I)
#7.GPIO 端口置位/复位寄存器 (GPIOx_BSRR) (x = A..I)
#8.GPIO 端口配置锁定寄存器 (GPIOx_LCKR) (x = A..I)
#9.GPIO 复用功能低位寄存器 (GPIOx_AFRL) (x = A..I)
#10.GPIO 复用功能高位寄存器 (GPIOx_AFRH) (x = A..I)
操作方法如下
GPIOx->MODER &= ~(0x3<<(2*PIN_NUM));
GPIOx->MODER |= (0x0<<(2*PIN_NUM));
GPIOx->MODER &= ~(0x3<<(2*PIN_NUM));
GPIOx->MODER |= (0x1<<(2*PIN_NUM));
GPIOx->MODER &= ~(0x3<<(2*PIN_NUM));
GPIOx->MODER |= (0x2<<(2*PIN_NUM));
GPIOx->MODER &= ~(0x3<<(2*PIN_NUM));
GPIOx->MODER |= (0x3<<(2*PIN_NUM));
GPIOx->OTYPER &= ~(0x1<<(PIN_NUM));
GPIOx->OTYPER |= (0x0<<(PIN_NUM));
GPIOx->OTYPER &= ~(0x1<<(PIN_NUM));
GPIOx->OTYPER |= (0x0<<(PIN_NUM));
GPIOx->OSPEEDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->OSPEEDR |= (0x0<<(2*PIN_NUM));
GPIOx->OSPEEDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->OSPEEDR |= (0x1<<(2*PIN_NUM));
GPIOx->OSPEEDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->OSPEEDR |= (0x2<<(2*PIN_NUM));
GPIOx->OSPEEDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->OSPEEDR |= (0x3<<(2*PIN_NUM));
GPIOx->PUPDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->PUPDR |= (0x0<<(2*PIN_NUM));
GPIOx->PUPDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->PUPDR |= (0x1<<(2*PIN_NUM));
GPIOx->PUPDR &= ~(0x3<<(2*PIN_NUM));
GPIOx->PUPDR |= (0x2<<(2*PIN_NUM));
((GPIOx->IDR&(0x1<<PIN_NUM))>>PIN_NUM))
GPIOx->ODR &= ~(0x1<<PIN_NUM);
GPIOx->ODR |= (0x0<<PIN_NUM);
GPIOx->ODR &= ~(0x1<<PIN_NUM);
GPIOx->ODR |= (0x1<<PIN_NUM);
GPIOx->BSRR &= ~(0x1<<(16+PIN_NUM));
GPIOx->BSRR |= (0x1<<(16+PIN_NUM));
GPIOx->BSRR &= ~(0x1<<PIN_NUM);
GPIOx->BSRR |= (0x1<<PIN_NUM);
GPIOx->AFRL &= ~(0x1<<16);
GPIOx->AFRH &= (0x0<<16);
GPIOx->LCKR &= ~(0x1<<16);
GPIOx->LCKR |= (0x1<<16);
GPIOx->AFRL &= ~(0xf<<(4*PIN_NUM));
GPIOx->AFRL |= ((AF_NUM)<<(4*PIN_NUM));
GPIOx->AFRH &= ~(0xf<<(4*(PIN_NUM-8)));
GPIOx->AFRH |= ((AF_NUM)<<(4*(PIN_NUM-8)));
|