Sub topic 13
Wiring, Signal Integrity, and Voltage Levels
This chapter assumes you understand Arduino sketches, digital I/O, hexadecimal values, bitwise operators, and basic breadboard wiring. It focuses on making SPI signals reliable after the software settings are correct.
Use a complete electrical connection
SPI normally uses four signals:
- SCLK is the controller's clock output.
- MOSI carries data from the controller to a peripheral.
- MISO carries data from the peripheral to the controller.
- CS selects one peripheral. It is usually active low.
Connect the controller and peripheral grounds. A signal voltage has meaning only relative to a shared reference. Without a common ground, a logic analyzer may show activity while the peripheral reads random values.
Keep the wires short and route the signal wires near a ground wire when possible. Long parallel wires add capacitance and allow signals to couple into one another. SCLK is especially sensitive because every edge controls when data is sampled.
Match logic voltage levels
Check the voltage for both the Arduino board and the peripheral. A 5 V controller can damage a 3.3 V-only peripheral, even if the SPI protocol is otherwise correct. A 3.3 V controller may also fail to produce a valid high level for a 5 V peripheral.
| Connection | Check |
|---|---|
| Controller output to peripheral input | The peripheral accepts the controller's high and low voltages |
| Peripheral output to controller input | The controller input is not over-voltage |
| Power supply | The peripheral receives its specified supply voltage |
| Ground | Both devices share a suitable ground reference |
A level shifter converts logic levels between voltage domains. Use one that supports push-pull signals and the required SPI clock rate. Simple resistor dividers can reduce a controller's output voltage, but they slow edges and are usually a poor choice for fast SCLK signals. MISO also needs translation in the opposite direction.
Control ringing and loading
Fast edges can overshoot, undershoot, or ring when wires and input capacitance form a transmission-line effect. Symptoms include intermittent reads, errors that appear only at higher clock rates, or different behavior when you touch a wire.
Try these changes in order:
- Lower the SPI clock rate.
- Shorten the wires and remove unnecessary breadboard connections.
- Place a small series resistor, often about 22–100 ohms, near the signal driver.
- Add local supply decoupling near the peripheral, following its datasheet.
- Verify the ground connection and power supply under load.
A series resistor slows the edge slightly and reduces reflected energy. Choose its value by observing the waveform rather than treating the range as universal.
Diagnose the physical layer
Use a logic analyzer at the peripheral pins, not only at the Arduino pins. Confirm that CS changes cleanly, SCLK reaches the expected high and low levels, and MISO is released when that peripheral is deselected. If the waveform is clean but the reply is wrong, return to the peripheral's SPI mode, bit order, and command format.
Exercise
An SPI peripheral works at 500 kHz but returns corrupted data at 8 MHz. Name two physical changes to try before changing the command code.
Show answer
Shorten the signal and ground wires, and reduce ringing with a suitable series resistor near the driver. Also verify the power decoupling and shared ground.