Specialist Supplier of Crystals & Frequency Control Componentssales@mecxtal.com.cn0755-26500570
MERLIN home / Rednote / System Validation and Replacement

Why AVR SPI master can lose SCK on a 20 MHz crystal board

An ATmega1284P logger controls several serial peripherals. Its 20 MHz passive crystal is running and other timing functions continue. A different production fixture occasionally leaves SCK silent before a send, sometimes with an extra SPI interrupt. Check the direction and level of the hardware SS pin, then read the master-mode bit. SS can affect the controller's role even when another GPIO serves as the peripheral select.

The hardware SS pin still controls role detection

The data sheet describes master-mode SS separately for input and output. As an output, it can be a general output without this role-detection effect. As an input, hold it high. If external circuitry pulls it low while the peripheral is configured as master, hardware clears MSTR, changes MOSI and SCK to inputs and raises the SPI flag. A board pull can then hold SCK at one level even though the rest of the controller runs.

Find the dedicated SS on the actual package and the GPIO used to select each peripheral. They may or may not be the same. If a board uses the hardware pin as an auxiliary input, consider its normal and test values. An expansion fixture that pulls an otherwise high signal low can cause a role change. Record direction, default level and attached load.

Predict valid SCK and locate the first missing edge

Assume a verified undivided 20 MHz system clock from the 20 MHz passive crystal with operating voltage suitable for the speed grade. Divide-by-four gives 5 MHz or 200 ns per SCK period. Eight continuous clocks take a nominal 1.6 µs, excluding select timing and software gaps. A verified effective divide-by-two configuration gives 10 MHz or 0.8 µs per byte. These figures assume the peripheral remains master. Divider readback cannot restore SCK after MSTR falls.

Capture hardware SS, the real peripheral select, SCK and a software marker. First verify a normal byte. During failure, look for a low on SS before the first missing clock. Preserve status in the interrupt before restarting the peripheral. The interrupt flag can reflect the role change and should not count as a completed byte without checking. Compare MSTR, transmit queue and captured edges.

Establish the required pin state before running the interface

On a single-master design, configuring hardware SS as an output is an option if the board allows it. Choose the correct default for the connected load. If it must remain an input, verify that it stays high through reset, normal operation and fixture connection. Use a controlled unloaded bench with documented electrical limits to compare configurations. Do not short a pin that may actively drive.

Check initialization order too. Code that enables SPI master before configuring the pin can expose the first transaction to a different condition. Establish direction and default level before enabling operation according to the design. If hardware changes role, decide whether to discard the interrupted frame, release the real select and issue it again. Count a successful retry separately from a first-pass success.

Compare old and new fixtures without changing firmware. Capture hardware SS and the first transaction under identical supply and reset conditions. If only the new fixture fails, establish whether it drives the line, adds a pull or changes sequencing. If both fail on cold start, include reset and clock readiness. The pin state just before SCK disappears matters more than a much later plateau.

Check default input state with the installed load, including the period when a peripheral is unpowered. Compare the board alone with the actual harness and record both rails. Locate the branch that changes SS before choosing a fix. Re-enabling master unconditionally can hide that cause.

If MSTR remains set and the pin is unchanged, verify the actual data-register write, peripheral enable and pin configuration. Save a passing first frame as a reference for the next board.

Record the 20 MHz passive crystal, measured system rate, SPI divider, hardware SS direction and real peripheral selects. Cover cold start and repeated communication with the actual fixtures. Save MSTR and the first frame on failure. Verify serial rate when clocking changes and pin behavior when wiring changes. The capture should explain why SCK stopped where it did.

References

WeChat

MERLIN · TIMING COMPONENTS

Scan with WeChat to contact Sales

Add our WeCom contacts from your usual WeChat app.

On desktop, scan with your phone. On mobile, save the QR image and select it from your album in WeChat Scan.