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.
Breaking it down
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.
| Level | Time | Works in simulation only? |
|---|---|---|
| Advanced | 12 hours | Simulation 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.
| Item | What it is (in simple words) | Why you need it | Approx. 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 module | A 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 wires | A 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 |
| Multimeter | Measures 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 useful | A 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
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| sclk | output | SD CLK | start below 400 kHz |
| mosi | output | SD DI | |
| miso | input | SD DO | |
| cs_n | output | SD CS |
Step 1: simulate the design
CMD0 must end with CRC byte 0x95; the frame builder shows how it is calculated.
Step by step
- Build and verify the CRC7 function in simulation.
- Send 80 clocks with CS high, then CMD0 and wait for response 0x01.
- Send CMD8, then ACMD41 until the card leaves idle.
- Write one 512-byte block with CMD24.
- Use a card holder with level shifting if it runs on 5 V.
If it does not work
| Symptom | Likely cause | Fix |
|---|---|---|
| Board not detected | Charge-only cable or no driver | Use a data cable, install the vendor driver |
| Nothing happens | Wrong pin constraints | Recheck every pin against the board manual |
| No response | SPI clock too fast at start | Use under 400 kHz |
| Card gets hot | Wrong supply voltage | Use 3.3 V only |
Quick quiz
1. CRC byte for CMD0?
Known fixed value.