Microcontroller I/O — Cheat Sheet

GPIO, pull-ups, PWM, ADC, I²C/SPI/UART timing, interrupts and debounce.

GPIO

Pull-up/downtyp. 10 kΩ external; internal ~20–50 kΩ
Drive strengthcheck I_OL/I_OH per pin AND total per port
Open-drainneeds a pull-up; allows level shifting / wired-AND
Unused pinsdrive or pull — never leave floating (CMOS)
Debounce10–50 ms, or RC + Schmitt input

PWM & timers

Frequencyf = f_clk / (prescaler × (ARR + 1))
Resolution (bits)log₂(timer period counts)
DutyCCR / (ARR + 1)
Motor PWM≥ 20 kHz to stay out of audible range

ADC

Value → voltsV = code · V_ref / 2ⁿ
Source impedancekeep low, or lengthen sample time
Sample timeτ = R_src · C_sh; allow ≥ 10τ
Referenceaccuracy is limited by V_ref, not the ADC

Serial buses

I²C2 wires, addressed, pull-ups required; 100k/400k/1M
SPI4 wires, full duplex, fastest, one CS per device
UART2 wires, no clock — both ends must agree on baud
CANdifferential, robust, 120 Ω termination each end
RS-485differential multi-drop, 120 Ω termination

Interrupts

ISR ruleshort — set a flag, do work in the main loop
Shared datamark `volatile`; guard multi-byte access
Prioritywatch for inversion and nesting

Formula reference — verify against the governing standard. Not a substitute for engineering judgment.