Microcontroller I/O — Cheat Sheet
GPIO, pull-ups, PWM, ADC, I²C/SPI/UART timing, interrupts and debounce.
GPIO
| Pull-up/down | typ. 10 kΩ external; internal ~20–50 kΩ |
| Drive strength | check I_OL/I_OH per pin AND total per port |
| Open-drain | needs a pull-up; allows level shifting / wired-AND |
| Unused pins | drive or pull — never leave floating (CMOS) |
| Debounce | 10–50 ms, or RC + Schmitt input |
PWM & timers
| Frequency | f = f_clk / (prescaler × (ARR + 1)) |
| Resolution (bits) | log₂(timer period counts) |
| Duty | CCR / (ARR + 1) |
| Motor PWM | ≥ 20 kHz to stay out of audible range |
ADC
| Value → volts | V = code · V_ref / 2ⁿ |
| Source impedance | keep low, or lengthen sample time |
| Sample time | τ = R_src · C_sh; allow ≥ 10τ |
| Reference | accuracy is limited by V_ref, not the ADC |
Serial buses
| I²C | 2 wires, addressed, pull-ups required; 100k/400k/1M |
| SPI | 4 wires, full duplex, fastest, one CS per device |
| UART | 2 wires, no clock — both ends must agree on baud |
| CAN | differential, robust, 120 Ω termination each end |
| RS-485 | differential multi-drop, 120 Ω termination |
Interrupts
| ISR rule | short — set a flag, do work in the main loop |
| Shared data | mark `volatile`; guard multi-byte access |
| Priority | watch for inversion and nesting |
Formula reference — verify against the governing standard. Not a substitute for engineering judgment.