Módulo GPIO
STM32F746ZG
Board Configuration-Up view
Board Configuration-Bottom view
Board Configuration-Bottom view
Main Elements
Main Elements
User LED1: Led de color verde conectado al pin
PB0.
User LED2: Led de color azul conectado al pin
PB7.
User LED 3: Led de color rojo conectado al pin
PB14.
Main Elements
LD4 COM: Led tricolor (verde, naranja, rojo).
Proporciona información sobre el estado del
enlace ST-LINK.
Naranja:Falla en comunicación.
Rojo: Inicialización entre PC y ST-LINK es
correcta.
Verde: La comunicación finalizó correctamente.
Main Elements
Push Buttons:
B1 User: Conectado al pin PC13.
B2 Reset: Botón de reset del microcontrolador.
GPIO-I/O Ports
GPIO-I/O Ports
Cada puerto tiene cuatro registros (32 bits) de
configuración:
GPIOx_MODER
GPIOx_OTYPER
GPIOx_OSPEEDR
GPIOx_PUPDR
Y dos registros (16 bits) para lectura y escritura:
GPIOx_IDR: Para entradas.
GPIOx_ODR: Para salidas.
GPIO-I/O Ports
GPIO port mode register: GPIOx_MODER.
GPIO-I/O Ports
GPIO port mode register: GPIOx_MODER.
Ejemplo:
GPIOB→MODER=0x10004001;
Equivale a tener:
0001 0000 0000 0000 0100 0000 0000 0001
PB 14 7 0
GPIO-I/O Ports
GPIO port mode register: GPIOx_MODER.
Ejercicio: Configure el puerto C con el fin de
tener como salidas los pines PC2 y PC3.
GPIO-I/O Ports
GPIO port output type register:
GPIOx_OTYPER.
GPIO-I/O Ports
GPIO port output type register:
GPIOx_OTYPER.
GPIO-I/O Ports
GPIO port output type register:
GPIOx_OTYPER.
Push pull: Un ‘0’ en el registro de salida activa el
transistor N-MOS, mientras que un ‘1’ activa el transistor
P-MOS.
Open drain: Un ‘0’ en el registro de salida activa el
transistor N-MOS, mientras que un ‘1’ deja el puerto en
alta impedancia.
Nota: Cuando se configura un pin como salida, los datos son
muestreados a la velocidad definida por el reloj del registro
correspondiente.
GPIO-I/O Ports
GPIO port output type register:
GPIOx_OTYPER.
Ejemplo:
GPIOB->TYPER=0;
GPIO-I/O Ports
GPIO port pull-up/pull-down register:
GPIOx_PUPDR
GPIO-I/O Ports
GPIO port pull-up/pull-down register:
GPIOx_PUPDR.
Cuando el pin se configura como entrada se desactiva la salida. El
Schmitt trigger elimina el ruido de entrada. El muestreo depende
del reloj del registro.
GPIO-I/O Ports
GPIO port pull-up/pull-down register:
GPIOx_PUPDR.
Ejemplo:
GPIOB->PUPDR=0x10004001;
GPIO-I/O Ports
GPIO port output speed register:
GPIOx_OSPEEDR.
GPIO-I/O Ports
GPIO port output speed register:
GPIOx_OSPEEDR.
Ejemplo:
GPIOB->OSPEEDR=0x10004001;
GPIO-Reloj de Registros de Puertos
RCC AHB1 peripheral clock
register:RCC_AHB1ENR.
Bits 0 a 10 controlan el reloj de los registros de los
puertos A-K.
1: activado.
0: desactivado.
GPIO-Reloj de Registros de Puertos
RCC AHB1 peripheral clock
register:RCC_AHB1ENR.
Ejemplo:
RCC→AHB1ENR |=0x08;
Activa el reloj del registros para el puerto D. La
instrucción |= evita que se deshabilite los relojes
previamente activados.
GPIO-Ejemplo
#include <stdio.h>
#include "STM32F7xx.h"
int time=500000;
int main (void)
{
int i=0;
RCC->AHB1ENR |=(1UL<<1); //RCC (register clock control) // AHB1ENR (AHB stands for AH bus
inside the micropocessor, 1 is the index of register, and comes ENable Register) // this line enable
clock for ports
GPIOB->MODER=0x10004001;
GPIOB->OTYPER=0;
GPIOB->OSPEEDR=0x10004001;
GPIOB->PUPDR=0x10004001;
while(true){
GPIOB->ODR |=(1UL<<14);
for(i=0;i<time;i++);
GPIOB->ODR &= ~(1UL<<14);
for(i=0;i<time;i++);
}
}
GPIO-Ejercicio: Disp. 7 segm.
Puerto B:
12 11 2 1 15 14 13
A BCD E F G
GPIO-Ejercicio: Disp. 7 segm.
#include <stdio.h>
#include "STM32F7xx.h"
int time=500000;
int main (void)
{
int i=0;
RCC->AHB1ENR = 0x2;
GPIOB->MODER=0x55400014;
GPIOB->OTYPER=0;
GPIOB->OSPEEDR=0x55400014;
GPIOB->PUPDR=0x55400014;
while(true){
for(i=0;i<time;i++);
GPIOB->ODR =0x2000;
for(i=0;i<time;i++);
GPIOB->ODR =0xF002;
for(i=0;i<time;i++);
GPIOB->ODR =0x4004;
for(i=0;i<time;i++);
GPIOB->ODR =0xC000;
}
}