Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
stm32:peripherals:gpio_output [2016/02/26 13:14] – [Programming Example] feurstm32:peripherals:gpio_output [2022/12/28 08:17] (current) ruan
Line 10: Line 10:
 \\ {{gpio_output.svg}} \\ \\ \\ {{gpio_output.svg}} \\ \\
  
-===== Programming Example =====+===== Programming Instructions =====
  
-The code snippet bellow shows how to configure and use a GPIO pin as output.+==== Enable Peripheral ====
  
-<code c> +Make sure the peripheral is enabled: 
-#include "reg_stm32f4xx.h"+  * Enable GPIOx in ''RCC->AHBENR[0]''.
  
-RCC->AHBENR[0] |(0x1 << 0u);    /* Enable GPIOA clock */+==== Setup output mode ====
  
-/* Configure GPIO pin A.5 as output. */ +Configure the MODE and PUPDR as well as the output type and speed register, \\ for every pin that should act as digital output: 
-GPIOA->MODER &= ~(0x3 << 10u);    /Clear existing mode bits 10 and 11. */ +  Write ''0x01'' to the corresponding fields in ''GPIOx->MODE''
-GPIOA->MODER |= (0x1 << 10u);     /* Set pin 10 to pull-up mode*/ +  Configure pull-up / -down in ''GPIOx->PUPDR''. 
- +  Configure output type in ''GPIOx->OTYPER''. \\ (in conjunction with ''GPIOx->PUPDR'') 
-GPIOA->PUPDR &= ~(0x3 << 10u);    /Clear existing pull-up/-down bits 10 and 11. */ +  Configure output speed in ''GPIOx->OSPEEDR''.
-GPIOA->PUPDR |= (0x2 << 10u);     /* Set pin 5 to pull-down mode. *+
- +
-GPIOA->OTYPER &= ~(0x1 << 5u);    /* Clear existing output type bit 5. */ +
- +
-GPIOA->OSPEEDR &= ~(0x3 << 10u) /Clear existing output speed bits 10 and 11. */ +
-GPIOA->OSPEEDR |= (0x1 << 10u);   /* Set pin 5 to medium speed (10 MHz) mode*/ +
- +
-/* Write to GPIO pin A.5. */ +
-GPIOA->IDR |= (0x1 << 5u);        /* Write to data register. */ +
- +
-GPIOA->BSRR[0] = (0x1 << 5u);     /* Directly set GPIO pin A.5. */ +
-GPIOA->BSRR[1] = (0x1 << 5u);     /* Directly clear GPIO pin A.5. */ +
-</code>+
 \\ \\
  
 ===== Configuration Registers ===== ===== Configuration Registers =====
  
-==== MODER ==== +==== GPIOx_MODER - Port mode register ====
- +
-Mode register+
  
 \\ {{gpio_reg_common.svg}} \\ \\ \\ {{gpio_reg_common.svg}} \\ \\
Line 50: Line 35:
 |Pin x|01|Output mode| |Pin x|01|Output mode|
  
-==== PUPDR ==== +==== GPIOx_PUPDR - Port pull-up / pull-down register ====
- +
-Push-up / pull-down register+
  
 \\ {{gpio_reg_common.svg}} \\ \\ \\ {{gpio_reg_common.svg}} \\ \\
Line 62: Line 45:
 |:::|11|Reserved| |:::|11|Reserved|
  
-==== OTYPER ==== +==== GPIOx_OTYPER - Port output type register ====
- +
-Output type register+
  
 \\ {{gpio_reg_otyper.svg}} \\ \\ \\ {{gpio_reg_otyper.svg}} \\ \\
Line 72: Line 53:
 |:::|1|Output type: open-drain| |:::|1|Output type: open-drain|
  
-==== OSPEEDR ==== +==== GPIOx_OSPEEDR - Port output speed register ====
- +
-Output speed register +
  
 \\ {{gpio_reg_common.svg}} \\ \\ \\ {{gpio_reg_common.svg}} \\ \\
Line 86: Line 65:
 ===== Data Registers ===== ===== Data Registers =====
  
-==== ODR ==== +==== GPIOx_ODR - Port output data register ====
- +
-Output data register+
  
 \\ {{gpio_reg_odr.svg}} \\ \\ \\ {{gpio_reg_odr.svg}} \\ \\
Line 96: Line 73:
 |:::|1|Set pin x| |:::|1|Set pin x|
  
-==== BSRR ==== +==== GPIOx_BSRR Port bit set / reset register ====
- +
-Bit set / reset register+
  
 \\ {{gpio_reg_bsrr.svg}} \\ \\ \\ {{gpio_reg_bsrr.svg}} \\ \\
Line 108: Line 83:
 |:::|1|Clear/reset pin x| |:::|1|Clear/reset pin x|
  
-===== Legend ===== 
- 
-\\ {{legende.svg}} \\ \\ 
  • stm32/peripherals/gpio_output.1456492452.txt.gz
  • Last modified: 2016/02/26 13:14
  • by feur