-
Notifications
You must be signed in to change notification settings - Fork 1
03. Module1_AnatomyOfAMicrocontroller
Mukul Yadav edited this page Sep 10, 2025
·
4 revisions
Before we can program a microcontroller at the register level, we need to understand how it's internally organised. This section breaks down a typical MCU block diagram and explains the essential building blocks you'll encounter across most platforms (like STM32, AVR, MSP430, etc.).
- The brain of the MCU. Executes instructions from your program.
- Common cores: ARM Cortex-M0/M3/M4, AVR, RISC-V, etc.
- Handles interrupts, arithmetic, logic, and program flow.
- Stores your compiled program (non-volatile).
- You flash your binary here via a programmer/debugger.
- Stores variables, stack, and runtime data.
- Volatile—cleared when the device resets or powers off.
- Provides timing signals to the entire chip.
- Sources: internal RC oscillator, external crystal, PLL (Phase Locked Loop).
- Critical for setting up peripherals and processor speed.
Common terms:
| Term | Description |
|---|---|
| HSI | High-Speed Internal Oscillator |
| HSE | High-Speed External crystal |
| SYSCLK | System Clock |
| AHB/APB | Clock buses for peripherals |
-
Digital input/output pins.
-
Can be configured for:
- Input (buttons)
- Output (LEDs)
- Alternate Function (UART, SPI, etc.)
-
Each GPIO port is usually connected to:
- A MODER register (mode: input/output/alternate)
- An ODR register (output data)
- An IDR register (input data)
- Measure time, generate delays, create PWM signals.
Common features:
- One-shot or periodic timing
- Compare & capture modes
- Input edge detection
- Handles interrupts from peripherals.
- Lets you pause main code to respond to events (like button press or UART input).
- Essential for low-latency systems.
| Peripheral | Use Case |
|---|---|
| UART | Serial communication (e.g., with PC, sensors) |
| SPI | Fast synchronous data transfer (e.g., displays, sensors) |
| I²C | Communicates with multiple devices on a shared bus |
| CAN | Used in automotive and industrial control systems |
These interfaces often share pins via pin multiplexing (more below).
- Converts analogue voltages (like from sensors) into digital numbers.
Key settings:
- Resolution (e.g., 10-bit, 12-bit)
- Sampling time
- Input channel
- Most MCU pins have multiple possible functions.
- Example: Pin A2 might be GPIO, UART TX, or ADC input.
- Function is selected using AF (Alternate Function) registers.
- AHB/APB buses connect the CPU with peripherals.
- Each peripheral lives at a fixed address in the memory map.
- Think of your MCU as a mini city with memory and peripherals wired together on a bus grid.
| Block | Description |
|---|---|
| CPU Core | Executes your code |
| Flash | Stores program |
| SRAM | Runtime memory |
| GPIO | Talk to external devices |
| Timers | Create delays, PWM |
| Clocks | Control timing for everything |
| Peripherals | UART, SPI, ADC, etc. |
Take a datasheet for your microcontroller (e.g., STM32F103C8) and identify:
- Clock sources
- Flash/SRAM size
- Number of GPIOs
- Available peripherals
- Pin multiplexing options
Created and maintained by Open Horizon® under the GNU AGPLv3 licence. Visit the full repository at https://github.com/openhorizonrobotics/E-2-ES