Projects / SRAM read and write lab

SRAM read and write lab

Intermediate1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO23LC1024

    Wire the chip

    SPI plus 5V and ground.

  2. NANO

    Write one byte

    Address 0.

  3. NANO

    Read it back

    Compare.

  4. NANO

    Test with 0x55

    Whole memory.

  5. NANO

    Test with 0xAA

    Whole memory.

  6. NANO

    Test with the address pattern

    Finds address faults.

  7. NANO

    Power-cycle

    See the data disappear.

In short

How do you build an SRAM read and write lab?

Write and read bytes in an SPI SRAM chip and test it with a pattern to understand memory. You need Arduino Nano, 23LC1024 SPI SRAM, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 60 minutes.

Level
Intermediate
Time
About 60 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
23LC1024 pin 1 (CS)Nano D10Chip select
23LC1024 pin 2 (SO)Nano D12 (MISO)Data out
23LC1024 pin 5 (SI)Nano D11 (MOSI)Data in
23LC1024 pin 6 (SCK)Nano D13Clock
23LC1024 pins 3 and 7Nano 5VUnused pins held high
23LC1024 pin 8 (VCC)Nano 5VPower
23LC1024 pin 4 (VSS)Nano GNDGround

Code

Static RAM keeps each bit in a small latch, so it reads and writes at full speed, but it forgets everything when power goes. The chip is a 128 KB 23LC1024 on SPI: send a command byte (2 to write, 3 to read), then a 3-byte address, then the data. First write one byte and read it back, then fill the whole memory with 0x55, then 0xAA, which exercises every bit both ways, and finally with data that depends on the address, which would reveal two addresses that map to the same cell. The report lists the first few bad addresses and the total. Unplug the board, reconnect it, and read address 0 again to see that the value has gone. The 23LC1024 runs from 2.5 to 5.5 V, so it is safe on the Nano's 5 V. Tie its unused pins high as shown, and keep the wires short. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// SRAM lab: write, read back and test the 23LC1024 (128 KB). Board: Arduino Nano.
#include <SPI.h>
const int CS = 10;
const uint32_t SIZE = 131072UL;
void ramBegin() {                                   // byte mode: one byte per command
  digitalWrite(CS, LOW); SPI.transfer(0x01); SPI.transfer(0x00); digitalWrite(CS, HIGH);
}
void ramWrite(uint32_t addr, uint8_t v) {
  digitalWrite(CS, LOW);
  SPI.transfer(0x02);
  SPI.transfer(addr >> 16); SPI.transfer(addr >> 8); SPI.transfer(addr);
  SPI.transfer(v);
  digitalWrite(CS, HIGH);
}
uint8_t ramRead(uint32_t addr) {
  digitalWrite(CS, LOW);
  SPI.transfer(0x03);
  SPI.transfer(addr >> 16); SPI.transfer(addr >> 8); SPI.transfer(addr);
  uint8_t v = SPI.transfer(0);
  digitalWrite(CS, HIGH);
  return v;
}
bool testPattern(uint8_t pattern, bool useAddress) {
  uint32_t bad = 0;
  for (uint32_t a = 0; a < SIZE; a++) ramWrite(a, useAddress ? (uint8_t)(a ^ (a >> 8)) : pattern);
  for (uint32_t a = 0; a < SIZE; a++) {
    uint8_t expect = useAddress ? (uint8_t)(a ^ (a >> 8)) : pattern;
    if (ramRead(a) != expect) { if (bad < 5) { Serial.print("Bad address "); Serial.println(a); } bad++; }
  }
  Serial.print(useAddress ? "Address pattern" : "Pattern 0x"); if (!useAddress) Serial.print(pattern, HEX);
  Serial.print(": bad bytes "); Serial.println(bad);
  return bad == 0;
}
void setup() {
  Serial.begin(115200);
  pinMode(CS, OUTPUT); digitalWrite(CS, HIGH);
  SPI.begin(); SPI.setClockDivider(SPI_CLOCK_DIV4);
  ramBegin();
  ramWrite(0, 0x42);
  Serial.print("Wrote 0x42 at address 0, read back 0x"); Serial.println(ramRead(0), HEX);
  testPattern(0x55, false);
  testPattern(0xAA, false);
  testPattern(0, true);                              // address-dependent data catches stuck address lines
  Serial.println("Power-cycle and read address 0 again: SRAM forgets without power.");
}
void loop() {}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Wrote 0x42 at address 0, read back 0x0
Bad address 0
Bad address 1
Bad address 2
Bad address 3
Bad address 4

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
One byteReads back 0x42
Each patternBad bytes 0
Address patternBad bytes 0
After power-cycleAddress 0 no longer holds 0x42

If it does not work

Reads 0xFF or 0x00

Check CS, SI and SO are not swapped.

Random bad bytes

Shorten the wires and slow the SPI clock.

No output

Check the baud rate of 115200.

Chip hot

Check VCC and VSS pins.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the SRAM read and write lab?

Arduino Nano, 23LC1024 SPI SRAM, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the SRAM read and write lab take to build?

About 60 minutes for a intermediate maker, in 7 steps.

How do I know the SRAM read and write lab works?

One byte: Reads back 0x42. Each pattern: Bad bytes 0. Address pattern: Bad bytes 0.

Reads 0xFF or 0x00: what should I check?

Check CS, SI and SO are not swapped.

Random bad bytes: what should I check?

Shorten the wires and slow the SPI clock.

No output: what should I check?

Check the baud rate of 115200.

Chip hot: what should I check?

Check VCC and VSS pins.