Changing the size of this SPI Ram

Hello

I am trying (without much luck so far), to get a 23K640 RAM connected to my Pro Mini

In the <SpiRAM.h> code, it states:

const uint32_t ramSize = 0x1FFFF; // 128K x 8 bit

This is for using a 23LC1024 ram chip. And I can’t see how that HEX value designates 8x 128.

Can someone please enlighten me? And therefore, how I would state 640k?

Pretty sure I have many other issues to yet overcome here (I don’t think these memory IC’s like breadboards much), but this is the first hurdle.

Thanks

Just in case anyone asks for the full code:

// Tested uning a 23LC1024 sRam chip in a 8 pin DIP package
// Test connections are...
// Chip UNO MEGA  NAME
//  1   9   9     SS    (Hardware SS Pin (10 or 53) needs to remain output no matter what other pin you may for SS)
//  2   12  50    MISO
//  3   NC  NC
//  4   GND GND   Vss
//  5   11  51    MOSI
//  6   13  52    SCK
//  7   +5V +5V   ~HOLD
//  8   +5V +5V   Vcc


#include <SPI.h>
#include <SpiRAM.h>

const uint32_t ramSize = 0x1FFFF;           // 128K x 8 bit
const byte LED = 13;

char buffer[] = {"ABCDEFGHIJ"};
char buffer2[sizeof(buffer)];

SpiRAM sRam(A1);                             // Initialize the RAM with non standard SS

void setup(){
  pinMode(LED,OUTPUT);
  digitalWrite(LED,LOW);                    // Turn off LED (Mega LED stays on else)
  Serial.begin(115200);
  Serial.println("Ram Tests Begin.");
  
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  
  Serial.println("\r\nFill Memory with 0xFF.");
  sRam.fillBytes(0,0xFF,ramSize);
  dumpsRam(0,100);
  dumpsRam(ramSize - 100, 100);

  Serial.println("\r\nFill Memory with 0xAA.");
  sRam.fillBytes(0,0xAA,ramSize);
  dumpsRam(0,100);
  dumpsRam(ramSize - 100, 100);

  Serial.println("\r\nFill Memory with Buffer.");
  for (uint32_t x = 0; x < ramSize - (sizeof(buffer) - 1); x += sizeof(buffer) - 1){
    sRam.writeBuffer(x, buffer, sizeof(buffer) - 1);
  }
  dumpsRam(0,100);
  dumpsRam(ramSize - 100, 100);

  Serial.println("\r\nRead Buffer.");
  sRam.readBuffer(0,buffer2,sizeof(buffer2) - 1);
  Serial.println(buffer2);
  sRam.readBuffer(5,buffer2,sizeof(buffer2) - 1);
  Serial.println(buffer2);

  Serial.println("\r\nWrite byte.");
  for (uint32_t x = 0; x <= ramSize; x++){
    if((x % 1024) == 0) digitalWrite(LED,!digitalRead(LED));
    sRam.writeByte(x, (byte) x / 10);
  }
  dumpsRam(0,100);
  dumpsRam(ramSize - 100, 100);

  Serial.println("\r\nRam Tests Finished.");
}

void loop(){
}

void dumpsRam(uint32_t addr, uint32_t length)
{
  // block to 10
  addr = addr / 10 * 10;
  length = (length + 9)/10 * 10;

  byte b = sRam.readByte(addr);
  for (int i = 0; i < length; i++)
  {
    if (addr % 10 == 0)
    {
      Serial.println();
      Serial.print(addr, HEX);
      Serial.print(":\t");
    }
    Serial.print(b, HEX);
    b = sRam.readByte(++addr);
    Serial.print("\t");
  }
  Serial.println();
}

void dumpsRam2(uint32_t addr, uint32_t length)
{
  // block to 10
  addr = addr / 10 * 10;
  length = (length + 9)/10 * 10;

  char b = sRam.readByte(addr);
  for (int i = 0; i < length; i++)
  {
    if (addr % 10 == 0)
    {
      Serial.println();
      Serial.print(addr);
      Serial.print(":\t");
    }
    Serial.print(b);
    b = sRam.readByte(++addr);
    Serial.print("\t");
  }
  Serial.println();
}

Sparky2019:
const uint32_t ramSize = 0x1FFFF; // 128K x 8 bit

This is for using a 23LC1024 ram chip. And I can't see how that HEX value designates 8x 128.

That would be the highest byte address available in a 128KB address space.

OK. BI found a page regarding this library, and it states:

address is an unsigned long (uint32_t) as addresses in the SPI RAM range from 0 to 131071 (2^17 – 1).

So, I still don't understand how to change that to suit my 640k IC?

A 64k byte RAM would have 0x1000 locations, 0 to 0xFFFF

The last location on a 128k byte (1024kbit) RAM would be 0x1FFFF.

Sparky2019:
So, I still don't understand how to change that to suit my 640k IC?

I'm not familiar with the part or library you're trying to use. But, why not try setting that variable to the highest byte address available in a 640KB address space?

OK thanks. I will have a play around.
I don't really understand this addressing stuff yet. Battered Google pretty hard so far.

My Serial monitor results are (with it set to 0xFFFF):

Ram Tests Begin.
Fill Memory with 0xFF.
*0: FF FF FF FF FF FF FF FF FF FF *
*A: FF FF FF FF FF FF FF FF FF FF *
*14: FF FF FF FF FF FF FF FF FF FF *
*1E: FF FF FF FF FF FF FF FF FF FF *
*28: FF FF FF FF FF FF FF FF FF FF *
*32: FF FF FF FF FF FF FF FF FF FF *
*3C: FF FF FF FF FF FF FF FF FF FF *
*46: FF FF FF FF FF FF FF FF FF FF *
*50: FF FF FF FF FF FF FF FF FF FF *
*5A: FF FF FF FF FF FF FF FF FF FF *
*FF96: 22 11 11 11 11 11 11 11 11 11 *
*FFA0: 11 11 11 11 11 11 11 11 11 11 *
*FFAA: 11 11 11 11 11 11 11 11 11 11 *
*FFB4: 11 11 11 11 11 11 11 11 11 11 *
*FFBE: 11 11 11 11 11 11 11 11 11 11 *
*FFC8: 11 11 11 11 11 11 11 11 11 11 *
*FFD2: 11 11 11 11 11 11 11 11 11 11 *
*FFDC: 11 11 11 11 11 11 11 11 11 11 *
*FFE6: 11 11 11 11 11 11 11 11 11 11 *
*FFF0: 11 11 11 11 11 11 11 11 11 11 *
Fill Memory with 0xAA.
*0: 3 C0 80 C2 0 FC 0 7C 80 0 *
*A: FF BF 0 7F 0 FC 82 1 80 1 *
*14: 42 B6 F0 60 1 82 0 FE 0 FC *
*1E: 0 0 40 0 FE 4 0 0 7F 80 *
*28: 82 0 4 40 0 1 7F 0 FE 80 *
*32: F8 2 FC 0 FC 0 FE 0 7F 0 *
*3C: 7C FF 0 FC 80 80 F0 80 8 7F *
*46: 8 F8 40 40 40 40 40 1 0 FE *
*50: 40 0 1 F0 8 F0 8 1 80 F0 *
*5A: FF 0 0 FC 70 0 0 FE 60 40 *
*FF96: 11 11 11 11 11 11 11 11 11 11 *
*FFA0: 11 11 11 11 11 11 11 11 11 11 *
*FFAA: 11 11 11 11 11 11 11 11 11 11 *
*FFB4: 11 11 11 11 11 11 11 11 11 11 *
*FFBE: 11 11 11 11 11 11 11 11 11 11 *
*FFC8: 11 11 11 11 11 11 11 11 11 11 *
*FFD2: 11 11 11 11 11 11 11 11 11 11 *
*FFDC: 11 11 11 11 11 11 11 11 11 11 *
*FFE6: 11 11 11 11 11 11 11 11 11 11 *
*FFF0: 11 11 11 11 11 11 11 11 11 11 *
Fill Memory with Buffer.
*0: 0 0 0 0 0 0 0 0 0 0 *
*A: 0 0 0 0 0 0 0 0 0 0 *
*14: 0 0 0 0 0 0 0 0 0 0 *
*1E: 0 0 0 0 0 0 0 0 0 0 *
*28: 0 0 0 0 0 0 0 0 0 0 *
*32: 0 0 0 0 0 0 0 0 0 0 *
*3C: 0 0 0 0 0 0 0 0 0 0 *
*46: 0 0 0 0 0 0 0 0 0 0 *
*50: 0 0 0 0 0 0 0 0 0 0 *
*5A: 0 0 0 0 0 0 0 0 0 0 *
*FF96: 0 0 0 0 0 0 0 0 0 0 *
*FFA0: 0 0 0 0 0 0 0 0 0 0 *
*FFAA: 0 0 0 0 0 0 0 0 0 0 *
*FFB4: 0 0 0 0 0 0 0 0 0 0 *
*FFBE: 0 0 0 0 0 0 0 0 0 0 *
*FFC8: 0 0 0 0 0 0 0 0 0 0 *
*FFD2: 0 0 0 0 0 0 0 0 0 0 *
*FFDC: 0 0 0 0 0 0 0 0 0 0 *
*FFE6: 0 0 0 0 0 0 0 0 0 0 *
*FFF0: 0 0 0 0 0 0 0 0 0 0 *
Read Buffer.
Write byte.
*0: 11 11 11 11 11 11 11 11 11 11 *
*A: 11 11 11 11 11 11 11 11 11 11 *
*14: 11 11 11 11 11 11 11 11 11 11 *
*1E: 11 11 11 11 11 11 11 11 11 11 *
*28: 11 11 11 11 11 11 11 11 11 11 *
*32: 11 11 11 11 11 11 11 11 11 11 *
*3C: 11 11 11 11 11 11 11 11 11 11 *
*46: 11 11 11 11 11 11 11 11 11 11 *
*50: 11 11 11 11 11 11 11 11 11 11 *
*5A: 11 11 11 11 11 11 11 11 11 11 *
*FF96: 11 11 11 11 11 11 11 11 11 11 *
*FFA0: 11 11 11 11 11 11 11 11 11 11 *
*FFAA: 11 11 11 11 11 11 11 11 11 11 *
*FFB4: 11 11 11 11 11 11 11 11 11 11 *
*FFBE: 11 11 11 11 11 11 11 11 11 11 *
*FFC8: 11 11 11 11 11 11 11 11 11 11 *
*FFD2: 11 11 11 11 11 11 11 11 11 11 *
*FFDC: 11 11 11 11 11 11 11 11 11 11 *
*FFE6: 11 11 11 11 11 11 11 11 11 11 *
*FFF0: 11 11 11 11 11 11 11 11 11 11 *
Ram Tests Finished.

So something isn't quite right somewhere.