Home / Learn Verilog / Project 15: SD Card Data Logger (SPI mode)

Project 15: SD Card Data Logger (SPI mode)

Initialize an SD card and write sensor samples.

Bottom lineInitialize an SD card and write sensor samples.

Breaking it down

SD loggersensorFIFOSD command FSMSPI masterSD card
SD logger

In plain terms

Use SPI mode to talk to an SD card: send CMD0 and CMD8 and log values. This project is about command framing and a CRC.

Why we use it

Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.

Under the hood

Simulate in the browser, then build for your board following the steps.

Real-world use

  • Portfolio
  • Interviews
  • Learning by doing

What you will build

Use SPI mode to talk to an SD card: send CMD0 and CMD8 and log values. This project is about command framing and a CRC.

LevelTimeWorks in simulation only?
Advanced12 hoursSimulation first

What you need (equipment and tools)

Read this table once and you will know exactly what to buy or prepare. You can do the simulation part with only a computer and the free tools.

ItemWhat it is (in simple words)Why you need itApprox. cost
Computer (Windows, Linux or macOS)Your normal laptop or desktop. You write Verilog here and run the free tools.Simulator, synthesis and programmer all run on it.you have it
Free software: Icarus Verilog + GTKWave (simulation), Yosys + nextpnr or the vendor IDE (build), openFPGALoader (program)The programs that compile and simulate your design.Everything in this course can be simulated with only these free tools.free
FPGA development board (e.g. Tang Nano 9K, Basys 3, iCEBreaker, Arty A7)A small circuit board with an FPGA chip, an oscillator (clock), LEDs, buttons and a USB port. The FPGA is the "blank hardware" that your Verilog turns into a real circuit.This is where your design actually runs. Without it you can only simulate.about $15 (Tang Nano 9K) to $150 (Arty A7)
microSD card + SPI microSD moduleA card socket board with SPI pins (CS, SCK, MOSI, MISO) and 3.3 V regulator/level shifter.Storage for the logger project.$3
Breadboard + jumper wiresA plastic board with holes connected in rows; wires plug in without soldering.Connect the FPGA pins to buttons, LEDs and modules quickly and safely.$5
MultimeterMeasures voltage, resistance and continuity.Check that a pin is 3.3 V, that wires connect, and that power is correct.$10
Logic analyzer (8-channel USB, e.g. Saleae-clone) - optional but very usefulA tool that records digital signals over time and shows them as waveforms on the PC, like the simulator but for the real board.Lets you check what the pins really do (UART bits, SPI clock, VGA sync).$10 for a clone, use with PulseView (free)

Connections

SignalDirectionGoes toNote
sclkoutputSD CLKstart below 400 kHz
mosioutputSD DI
misoinputSD DO
cs_noutputSD CS

Step 1: simulate the design

CMD0 frame builderVerilog: edit and run

CMD0 must end with CRC byte 0x95; the frame builder shows how it is calculated.

Step by step

  1. Build and verify the CRC7 function in simulation.
  2. Send 80 clocks with CS high, then CMD0 and wait for response 0x01.
  3. Send CMD8, then ACMD41 until the card leaves idle.
  4. Write one 512-byte block with CMD24.
  5. Use a card holder with level shifting if it runs on 5 V.

If it does not work

SymptomLikely causeFix
Board not detectedCharge-only cable or no driverUse a data cable, install the vendor driver
Nothing happensWrong pin constraintsRecheck every pin against the board manual
No responseSPI clock too fast at startUse under 400 kHz
Card gets hotWrong supply voltageUse 3.3 V only
Tip:Keep your first board test tiny: if the LED blinks, the toolchain, cable and clock are fine. Then add your project piece by piece.

Quick quiz

1. CRC byte for CMD0?