Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************
- GPIO Mode Register - GPIOx->MODER
- 00 = INPUT
- 01 = OUTPUT
- 10 = ALTERNATE FUNCTION
- 11 = ANALOG
- Example: Make LED pin output
- **********************************************************************/
- #define LED 3
- GPIOx->MODER |= (1 << (LED * 2)); //Set to Output
- /**********************************************************************
- GPIO Type Register - GPIOx->OTYPER
- 0 = PUSH-PULL (default)
- 1 = Open Drain
- Example: Make LED pin push-pull type
- **********************************************************************/
- #define LED 3
- GPIOx->OTYPER &= !(1 << LED); //Set to Push-Pull
- /**********************************************************************
- GPIO Output Speed Register - GPIOx->OSPEEDR
- 00 = 2MHz (Low Speed)
- 01 = 25MHz (Med. Speed)
- 10 = 50MHz (Fast Speed)
- 11 = 100MHz/80MHz (High Speed)(100MHz(30pf) - 80MHz(15pf))
- Example: Make LED pin 100MHz
- **********************************************************************/
- #define LED 3
- GPIOx->OSPEEDR |= (0x02 << (LED * 2)); //Set Max of 100MHz Speed
- /**********************************************************************
- GPIO Pull-Up / Pull-Down Register - GPIOx->PUPDR
- 00 = No Pull-Up / No Pull-Down
- 01 = Pull-Up Enabled
- 10 = Pull-Down Enabled
- 11 = Reserved
- Example: LED pin with NO PU/PD
- **********************************************************************/
- #define LED 3
- GPIOx->PUPDR &= (0x03 << (LED * 2)); //Set it for NO PUPD
- /**********************************************************************
- GPIO Input Data Register - GPIOx->IDR
- Read Pin State
- Example: Get input from button
- **********************************************************************/
- #define BTN 2
- variable = ((GPIOx->IDR >> BTN) & 1); //Get Button State
- /**********************************************************************
- GPIO Output Data Register - GPIOx->ODR
- Write Pin State
- Example: Turn on LED
- **********************************************************************/
- #define LED 3
- GPIOx->ODR |= (1<<LED); //Turn on LED
- /**********************************************************************
- GPIO Bit Set/Reset Register - GPIOx->BSRRn
- n = H (RESET)
- n = L (SET)
- Set or Reset Pins
- Example: Turn LED On then Off
- **********************************************************************/
- #define LED 3
- GPIOx->BSRRL |= (1<<LED); //Turn On LED
- GPIOx->BSRRH |= (1<<LED); //Turn Off LED
Advertisement
Add Comment
Please, Sign In to add comment