E - Interfacciamento dei microcontrollori
ES06 - Libreria Pulsanti
FB - 05.2021 - v1.1
Libreria pulsanti
Scrittura del codice in linguaggio C per la gestione dei pulsanti, da poter riutilizzare nei prossimi progetti.
2
© FB - 05.2021
Indice
3
© FB - 09.2019
Obiettivi didattici
4
Obiettivi didattici
5
© FB - 05.2021
Introduzione teorica
6
Prerequisito
7
© FB - 04.2022
Prerequisito
8
© FB - 04.2022
GPIO input: joystick
9
© FB - 04.2022
GPIO input: Joystick
10
© FB - 04.2019
Schema HW
11
© FB - 05.2021
Registers
12
© FB - 05.2021
Board Pin connections
13
© FB - 05.2021
GPIO pin configuration
Diversi registri del microcontrollore STM32L476 ci permettono la configurazione e l’utilizzo dei pin GPIO, ecco i principali:
where the 'x' in each register name acronym represents the port i.e. the GPIOx_MODER associated with port A is called GPIOA_MODER
14
© FB - 05.2021
AHB peripheral clock enable register
15
© FB - 05.2021
GPIO port mode register (GPIOx_MODER)
16
© FB - 05.2021
This is a 32-bit register where each set of two consecutive bits represent the mode of a single I/O pin. For example bits 0 and 1 of the MODER register associated with GPIOC (GPIOC_MODER), represent the mode of GPIO pin PC0 and bits 26 and 27 of the same register represent the mode of GPIO pin PC13.
Alternate function mode which allow the GPIO pins to be used by peripherals such as the UART, SPI e.t.c. It is important to note that if a pin's MODE is set to alternate function, any GPIO settings for that pin in the GPIO registers will be overridden by the peripheral. I will be addressing Alternate function mode in more detail in a future entry
GPIO port mode register (GPIOx_MODER)
17
© FB - 05.2021
GPIO port pull-up/pull-down register (GPIOx_PUPDR)
18
© FB - 04.2019
GPIO port pull-up/pull-down register (GPIOx_PUPDR)
19
© FB - 05.2021
GPIO port pull-up/pull-down register (GPIOx_PUPDR)
The GPIOx_PUPDR registers configures the internal pull-ups and pull-down resistors on each I/O pin. The internal pull-up/down resistors can be configured on GPIO pins set as input or output (though I'd imagine they'd be more popular on input pins). The Pullup/down resistors have a typical value of 40KOhms but can range from 30-50Kohms.
Again each two consecutive bits represent the internal pull-up/down resistor setting for each pin within a single port.
20
© FB - 04.2019
GPIO port pull-up/pull-down register (GPIOx_PUPDR)
21
© FB - 05.2021
22
GPIO port input data register (GPIOx _IDR)
This is a 16-bit read-only register. Each bit represents the input value on a corresponding pin. Reading a '0' in bit 8 of this GPIOC _IDR register indicates that the voltage on PC8 is 0V (GND). While reading a '1' in bit 8 of this GPIOC _IDR register indicates that the voltage on PC8 is 3.3V (VDD)
23
GPIO Configuration Modes�before
Esercitazione
24
Completare il codice
25
© FB - 06.2022
Completare il codice
26
© FB - 06.2022
Valutazione
27
Consegna del lavoro
Raccogliere in un documento, da aggiungere alla tabella progetti, i passaggi principali dell’esercitazione
28
© FB - 05.2021
Grazie per l’attenzione
29
Link/Riferimenti
30
Revisioni
v1.0 01/04/19 - versione iniziale �v1.1 07/05/21 - Aggiornata l’introduzione teorica e gli esercizi�v1.2 19/04/22 -
31