Practice 2 Asst Prof Dr Alper MAN GPIO
- Slides: 16
Practice 2 Asst. Prof. Dr. Alper ŞİŞMAN
GPIO Module • Output states: push-pull or open drain + pullup/down • Output data from output data register (GPIOx_ODR) or peripheral (alternate function output) • Speed selection for each I/O • Input states: floating, pull-up/down, analog • Input data to input data register (GPIOx_IDR) or peripheral (alternate function input) • Bit set and reset register (GPIOx_BSRR) for bitwise write access to GPIOx_ODR
• Locking mechanism (GPIOx_LCKR) provided to freeze the I/O configuration • Analog function • Alternate function input/output selection registers (at most 16 AFs per I/O) • Fast toggle capable of changing every two clock cycles • Highly flexible pin multiplexing allows the use of I/O pins as GPIOs or as one of several peripheral functions • During and just after reset, the alternate functions are not active and the I/O ports are configured in input floating mode.
The configuration steps of GPIO pin • The clock signal of corresponding GPIO HW must be activated: – RCC->AHB 1 ENR: Reset&Clock control reg. ->AHB 1 enable register. • The pins must be defined as input or output – GPIOD->MODER: Mode register 32 -bit for 16 pins:
• The output type must be configured – GPIOD=>OTYPER: • The output speed must be configured – GPIOD=>OSPEEDR: 32 bit register for 16 pins.
• The pull up resistor configuration mus be set – GPIOD=>PUPDR: 32 bit reg. 16 pins
Read/Write Registers • GPIO port input data register: GPIOD=>IDR • GPIO port output data reg. : GPIOD=>ODR • GPIO port bit set/reset reg. : GPIOD=>BSRR
Other GPIO Registers • GPIO port configuration lock reg. • GPIO alternate function low reg. • GPIO alternate function high reg. • Further information can be seen on page 278. (ref manual RM 0090)
Blinking LED • Run in DEBUG mode step by step and see four LED in on and off. • #include "STM 32 F 4 xx. h” • void System. Init() • { • (*((int*)0 x. E 000 ED 88))|=0 x 0 F 00000; // Floating Point donanimini aktiflestir. • RCC->AHB 1 ENR |= 0 x 00000008; // GPIOD donaniminin clock sinyalini uygulayalim • GPIOD->MODER = 0 x 55000000; // GPIOD nin 15, 14, 13, 12 pinleri cikis tanimlandi (Ledler bu pinlerde) • GPIOD->OSPEEDR= 0 x. FFFF; // GPIOD nin tum cikislari en yuksek hizda kullanacagiz • }
• int main() • { • while(1) • { • GPIOD->ODR= 0 x 0000 F 000; • GPIOD->ODR= 0 x 0000; • } // Ledler yansin // Ledler sonsun
Add a delay subrotine • void delayy(){ • int delay 0 = 0 x 000 FFFFF; • while (delay 0 --){ • }
Call delayy from main • int main() • { • while(1) • { • GPIOD->ODR= 0 x 0000 F 000; • delayy(); • GPIOD->ODR= 0 x 0000; • delayy(); • } // Ledler yansin // Ledler sonsun
Read Button • Activate GPIOA clock • Configure A 0 as input (it is default), bus speed and no pull up/down • void System. Init() • { • (*((int*)0 x. E 000 ED 88))|=0 x 0 F 00000; // Floating Point donanimini aktiflestir. • RCC->AHB 1 ENR |= 0 x 00000009; // GPIOD &A donaniminin clock sinyalini uygulayalim • GPIOD->MODER = 0 x 55000000; // GPIOD nin 15, 14, 13, 12 pinleri cikis tanimlandi (Ledler bu pinlerde) • GPIOD->OSPEEDR= 0 x. FFFF; // GPIOD nin tum cikislari en yuksek hizda kullanacagiz GPIOA->OSPEEDR= 0 x. FFFF; // GPIOA nin tum girisleri en yuksek hizda kullanacagiz • GPIOA->PUPDR = 0 x 0000; } •
Stop blinking • When button is pressed the blinking will stop: • int main() • { • while(1) • { • while ((GPIOA->IDR & 0 x 1) == 0){ • } • • GPIOD->ODR= 0 x 0000 F 000; // Ledler yansin • delayy(); • GPIOD->ODR= 0 x 0000; // Ledler sonsun • delayy(); • }
Define D 0 as output&observe it • void System. Init() • { (*((int*)0 x. E 000 ED 88))|=0 x 0 F 00000; // Floating Point donanimini aktiflestir. • RCC->AHB 1 ENR |= 0 x 00000009; // GPIOD &A donaniminin clock sinyalini uygulayalim • GPIOD->MODER = 0 x 55000001; // GPIOD nin 15, 14, 13, 12 ve 0. pinleri cikis tanimlandi (Ledler bu pinlerde+0. pin) • GPIOD->OSPEEDR= 0 x. FFFF; // GPIOD nin tum cikislari en yuksek hizda kullanacagiz • GPIOA->OSPEEDR= 0 x. FFFF; // GPIOA nin tum girisleri en yuksek hizda kullanacagiz
HW#2 • Connect a 7 -segment to the STM 32 F 4 x board • Write a number between 1 -9 on the 7 segment • When user button is pressed number 0 should be seen on the 7 -segment.
- Raspberry pi gpio nodejs
- Man vs what
- Man gpio
- Alper serdar anlı
- Dr ismail alper tarım
- Vertica
- Alper şişman
- Egeatasaglik
- 라즈베리파이4 gpio
- Webiopi raspberry pi 3
- Systeme d'exploitation
- /sys/class/gpio/gpiochip
- Module 'rpi.gpio' has no 'setmode' member
- Sin entered through one man
- You live to learn
- Volym massa densitet
- A hungry man is an angry man example sentence