Chapter 4 Digital Input and Output
Chapter 4 Digital Input and Output
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Table of Contents
1. Introduction
2. Microcontroller Architecture
3. Software Development Platforms
4. Digital Input and Output
5. Interrupts and Power Management
6. Timing Operations
7. Conversion Between Analog and Digital Values
8. Digital Communication
9. Memory Operations
10. Real-time Operating Systems
11. LCD, Touch Screen, and Graphical User Interface Formation
12. Introduction to Digital Signal Processing
13. Introduction to Digital Control
14. Introduction to Digital Image Processing
15. Advanced Topics
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
LAYOUT
Introduction
Bit Values as Voltage Levels
Interfacing Voltage Levels with the Microcontroller
Digital Input from a Switch or Button
Digital I/O with High Voltage Values
Digital Output to a Load Requiring High Current and Voltage
Values
Digital I/O Setup on the STM32F4 Microcontroller
Circuit Diagram of a Pin and Its Setup via Associated Registers
GPIO Registers in Memory Map of the STM32F4 Microcontroller
Setting Up GPIO Registers
Digital I/O Usage on the STM32F4 Microcontroller
C Language Usage
C++ Language Usage
MicroPython Usage
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Introduction
The microcontroller should interact with the outside world.
To do so, we will introduce interfacing digital input and output (digital I/O) to
and from the microcontroller in this chapter.
Peripheral units dedicated for this operation are called general purpose input
and output (GPIO) pins.
These will form a bridge between code-based bit values (logic level 0 or 1)
and voltage levels to be fed or received from the outside world.
We will show how the logic level 0 or 1 can be represented in voltage level.
We will deal with interfacing these voltage levels with the microcontroller.
We will focus on digital I/O setup within the STM32F4 microcontroller followed
by its usage.
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Bit Values as Voltage Levels
If we start interacting the
microcontroller with the outside
world, then abstract representations
such as logic level 0 or 1 do not
mean much.
LVTTL LVCMOS
3.3 V logic levels
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
Digital input from a switch or button
Switch bouncing is a serious problem when a
button (or switch) is used in a digital system.
Software solutions
adding a delay while reading the input in the code.
using a shift register.
Hardware Solution
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
Active high and low input circuit diagrams for the push button
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
Basic unidirectional
voltage level shifter
Basic bidirectional
voltage level shifter
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
BJT MOSFE
T
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Interfacing Voltage Levels with
the Microcontroller
bedded System Design with ARM Cortex-M Microcontrollers: Applications with C, C++ and MicroPython
Digital I/O Setup on the
STM32F4 Microcontroller