SD Card Logging Stops After Several Hours

Hello,
I’m building a data logger with a Raspberry Pi Pico and SPI SD card storage. Logging starts fine, but after several hours the file write process stalls and no new data is saved.

Power remains stable and the MCU does not crash.

Questions:

  1. Should I investigate filesystem handling first or SPI communication reliability?

  2. Can voltage dips during SD write current peaks cause silent failures?

  3. On the PCB, is it better to place the SD socket very close to the MCU SPI pins?

Start with filesystem and SD card behavior … SD cards often cause issues like:

Write latency spikes (internal erase/program cycles)
Full or fragmented FAT tables
Missing flush/sync calls leading to “looks fine but stuck writes”

SPI errors are possible, but “stalls after hours” is more commonly filesystem blocking or SD card internal busy states than pure SPI failure … read this discussion: https://electronics.stackexchange.com/questions/175614/spi-sd-card-communication-issues

  1. Can voltage dips during write peaks cause silent failures?

Yes … absolutely possible.

  1. PCB placement of SD socket?

Yes … keep it very close to MCU SPI pins … check this guide for placing pads on pcb: PCB Layout and The requirements of The Drawing of Pads - PCB Design & Layout - PCBway

Short SPI traces (especially SCK)
Tight routing over solid ground
Avoid routing near switching regulators or noisy digital lines
Add small series resistors, if edges are sharp