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

Why can an MFRC522 timeout differ by one tick with a healthy 27.12 MHz crystal?

A reader board with a 27.12 MHz surface-mount crystal has a one-millisecond receive timeout in its test script. The driver log shows occasional early or late exits, while the antenna appears unchanged. Three timestamps matter here: when the reader starts the timer, when the chip sets its timeout flag, and when the host reads and handles that flag. First test the hardware timer on its own in one-shot mode, then add the radio transaction and host software back to the picture.

Recompute both timer stages

Section 8.5 of the NXP data sheet gives the timer's input frequency. The MFRC522 derives a 13.56 MHz timer clock from its 27.12 MHz surface-mount crystal circuit. It then applies a 12-bit prescaler and a 16-bit countdown stage. With the default odd prescaler, a timer tick lasts two times the prescaler value plus one, divided by 13.56 MHz. The nominal delay takes the reload value plus one of these ticks. Using 27.12 MHz directly in that formula gives half the intended time.

With a prescaler of 169 and a reload value of 39, the default divisor is 339 and the tick is exactly 25 microseconds at nominal frequency. Forty ticks give 1.000 milliseconds. Using only 39 ticks gives 0.975 milliseconds, one entire tick short. On version 2.0 of the chip, setting DemodReg.TPrescalEven selects a divisor of 340. The same numeric configuration now gives about 1.00295 milliseconds. Each tick gained one source cycle, for a total of about 2.95 microseconds over 40 ticks. NXP lists this even prescaler option for version 2.0 only.

The 12-bit prescaler is split between a high field and a low register, while the 16-bit reload is written in two parts. Read back both complete fields after initialization, particularly if the initialization code is updating multiple controls in TModeReg. A reload write takes effect on the next start. Finish the preceding measurement before starting a new one with different settings.

Give the measurement a defined start

For the stand-alone timer test, use manual start with automatic start, gating, and auto-reload disabled. Clear the old timeout flag and start by writing ControlReg.TStartNow. Capture a marker for the host's register write and the enabled IRQ pin. Keep the 27.12 MHz surface-mount crystal, supply, and reset conditions constant as you change the reload. Read ComIrqReg to confirm the observed event was TimerIRq, because the pin can report other events too.

To reduce the influence of fixed host-write latency, compare reload values of 39 and 79 with the same 25-microsecond tick. Their nominal delays are 1.000 and 2.000 milliseconds, so the measured difference should be near one millisecond. Use the same bus transaction and IRQ observation points for both. A timestamp taken where the polling loop exits can include extra bus reads and scheduling. For the smaller 2.95-microsecond difference produced by even prescaling, first check that the measurement setup can resolve it.

In an actual transaction with TAuto set, the timer starts at the end of transmission. A host write that initiates transmission happens earlier and includes preparation and airtime if used as the timing origin. A received response can also stop the timer depending on the receive mode. To exercise the no-response path, keep the reader's transmit settings fixed, remove the responding endpoint, and use the transmit-complete event as the reference.

Inspect the driver's exit path

When the count reaches zero, the chip raises TimerIRq and can signal it on the IRQ pin if configured. As NXP explains, timer expiry during reception does not automatically end reception. A driver waiting for receive completion can remain active after hardware timer expiry, while a stale flag can make the next transaction appear to time out immediately. Record chip IRQ, the host's flag read, and actual exit from the transaction as separate events.

Use two acceptance checks for batches of reader boards with a 27.12 MHz surface-mount crystal. First, verify the measured difference between two manual timer settings and record the chip version and prescaler mode. Then verify that an unanswered transaction returns through the driver's intended timeout and clean-up path. If the first test passes and the second fails, correlate the IRQ and the driver log before changing the crystal circuit.

The two acceptance checks also help select a production fixture's time range. If all you can observe is a slow host log, leave the prescaler alone and temporarily change the reload from 39 to 799. The nominal delay goes from one to 20 milliseconds, yielding a difference of about 19 milliseconds under the same trigger conditions. That is large enough to test whether the new configuration takes effect, while the log still lacks the resolution to identify two close prescaler settings. Restore the production timeout after this fixture test.

For a cold-start investigation, retain traces from the first transaction and from repeated operation. An early host write may run before the oscillator and internal logic are ready to accept initialization. A successful warm retest narrows the inquiry, while register readback followed by the manual test can distinguish initialization timing from timer arithmetic. Keep board ID, chip version, crystal part number, and driver revision with the traces.

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.