Interface two 23LC1024 SRAMs with Arduino Uno using SPI

Hello everyone!

First up, I am new to all this so please be gentle!
Now what gives my headaches: I am trying to interface two 23LC1024 SRAMs with an Arduino Uno. I tried daisy-chaining the two SRAMs, but only the first one seems to be written to correctly.
I tested both SRAMs on their own - so it does not seem to be a hardware problem (unless I messed up the wiring - diagram attached).

Here is the code I am using:

#include <SPI.h>

#define RDSR      5
#define WRSR      1
#define READ      3
#define WRITE     2

uint8_t cs_pin[2] = {10, 9};   //chip select pins

//Byte transfer function - read 
void Spi23LC1024Read8(uint32_t address, uint8_t cs_pin) {
  uint8_t read_byte;
  digitalWrite(cs_pin, LOW);

  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16));
  SPI.transfer((uint8_t)(address >> 8));
  SPI.transfer((uint8_t)address);
  read_byte = SPI.transfer(0x00);

  digitalWrite(cs_pin, HIGH);

  Serial.print("READ: address: ");
  Serial.print(address);
  Serial.print(", value: ");
  Serial.println(read_byte);
}

//Byte transfer function - write 
void Spi23LC1024Write8(uint32_t address, uint8_t data_byte, uint8_t cs_pin) {
  digitalWrite(cs_pin, LOW);

  SPI.transfer(WRITE);
  SPI.transfer((uint8_t)(address >> 16));
  SPI.transfer((uint8_t)(address >> 8));
  SPI.transfer((uint8_t)address);
  SPI.transfer(data_byte);

  digitalWrite(cs_pin, HIGH);
}

void setup(void) {
  uint32_t i;

  Serial.begin(9600);
  SPI.begin();
  
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);

  Serial.println("For SRAM 1 (pin 10):");
  for (i = 0; i < 32; i++) {
    Spi23LC1024Write8(i, (uint8_t)i, cs_pin[0]);
  }
    
  for (i = 0; i < 32; i++) {
    Spi23LC1024Read8(i, cs_pin[0]);
  }

  Serial.println("For SRAM 2 (pin 9):");
  for (i = 0; i < 32; i++) {
    Spi23LC1024Write8(i, (uint8_t)i, cs_pin[1]);
  }
    
  for (i = 0; i < 32; i++) {
    Spi23LC1024Read8(i, cs_pin[1]);
  }
}

void loop() {
}

And the output I am getting:

For SRAM 1 (pin 10)

READ: address: 0, value: 0

READ: address: 1, value: 1

READ: address: 2, value: 2

READ: address: 3, value: 3

READ: address: 4, value: 4

READ: address: 5, value: 5

READ: address: 6, value: 6

READ: address: 7, value: 7

READ: address: 8, value: 8

READ: address: 9, value: 9

READ: address: 10, value: 10

READ: address: 11, value: 11

READ: address: 12, value: 12

READ: address: 13, value: 13

READ: address: 14, value: 14

READ: address: 15, value: 15

READ: address: 16, value: 16

READ: address: 17, value: 17

READ: address: 18, value: 18

READ: address: 19, value: 19

READ: address: 20, value: 20

READ: address: 21, value: 21

READ: address: 22, value: 22

READ: address: 23, value: 23

READ: address: 24, value: 24

READ: address: 25, value: 25

READ: address: 26, value: 26

READ: address: 27, value: 27

READ: address: 28, value: 28

READ: address: 29, value: 29

READ: address: 30, value: 30

READ: address: 31, value: 31

For SRAM 2 (pin 9)

READ: address: 0, value: 31

READ: address: 1, value: 223

READ: address: 2, value: 0

READ: address: 3, value: 215

READ: address: 4, value: 255

READ: address: 5, value: 0

READ: address: 6, value: 0

READ: address: 7, value: 255

READ: address: 8, value: 255

READ: address: 9, value: 255

READ: address: 10, value: 255

READ: address: 11, value: 0

READ: address: 12, value: 0

READ: address: 13, value: 0

READ: address: 14, value: 0

READ: address: 15, value: 251

READ: address: 16, value: 255

READ: address: 17, value: 255

READ: address: 18, value: 255

READ: address: 19, value: 255

READ: address: 20, value: 255

READ: address: 21, value: 255

READ: address: 22, value: 255

READ: address: 23, value: 0

READ: address: 24, value: 255

READ: address: 25, value: 0

READ: address: 26, value: 0

READ: address: 27, value: 0

READ: address: 28, value: 0

READ: address: 29, value: 0

READ: address: 30, value: 0

READ: address: 31, value: 255

What am I doing wrong? Any comments will be greatly appreciated (and when I say greatly, I actually mean you’ll be my hero forever!) :grinning:

P.S. Apologies if this is not the right place for this topic… wasn’t exactly sure where to post is

F8QVWQQI6KN8WGB.MEDIUM.jpg

Lealine:
Hello everyone!

First up, I am new to all this so please be gentle!
Now what gives my headaches: I am trying to interface two 23LC1024 SRAMs with an Arduino Uno. I tried daisy-chaining the two SRAMs, but only the first one seems to be written to correctly.
I tested both SRAMs on their own - so it does not seem to be a hardware problem (unless I messed up the wiring - diagram attached).

What am I doing wrong? Any comments will be greatly appreciated (and when I say greatly, I actually mean you'll be my hero forever!) :grinning:

P.S. Apologies if this is not the right place for this topic.. wasn't exactly sure where to post is

Code looks good, The only recommendation I can offer is to add a couple of bypass capacitors 0.1uf to each SRAM, between Vcc and Gnd.

Also, Breadboards are notorious for bad connections. Try using a different section of your breadboard.

Chuck.

Thanks for your reply! I used a different section of my breadboard, I even tried a brand new one, but that didnt do the trick... BUT, I added a pull-up resistor to the first SRAM and... IT WORKS!!!!! I tried adding a pull up resistor to both SRAMs, but that doesnt change anything.. only adding it to the first one does the trick..

So basically, it works, but I don't know why.. Any thoughts?

Lealine:
Thanks for your reply! I used a different section of my breadboard, I even tried a brand new one, but that didnt do the trick... BUT, I added a pull-up resistor to the first SRAM and... IT WORKS!!!!! I tried adding a pull up resistor to both SRAMs, but that doesnt change anything.. only adding it to the first one does the trick..

So basically, it works, but I don't know why.. Any thoughts?

pull up were?

Chuck.