Expanding memory of 2560 with 23k640 SRAM

Hello,
I have a project where I need a 6K RAM just to store waveform (6 waveform each of 1024 byte) for comparison, and as mega just have 8K RAM i need some more RAM and as I used mega 2560 before dont want to switch to new family controolers, so I checked SRAM ICS and found 23K640

Now I am trying to use it but dont no why it is not responding.
Here is my schematic


and code is from library example

/*
 * Driver for Microchip Technology Inc. 23LC (23LCV) SPI SRAM chips for
 * AVR, SAM3X (Due), and SAM M0+ (SAMD, SAML, SAMC) microcontrollers
 * 
 * Copyright (c) 2017, Justin Mattair (justin@mattair.net)
 * 
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for any purpose and without fee is hereby
 * granted, provided that the above copyright notice appear in all
 * copies and that both that the copyright notice and this
 * permission notice and warranty disclaimer appear in supporting
 * documentation, and that the name of the author not be used in
 * advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 *
 * The author disclaim all warranties with regard to this
 * software, including all implied warranties of merchantability
 * and fitness.  In no event shall the author be liable for any
 * special, indirect or consequential damages or any damages
 * whatsoever resulting from loss of use, data or profits, whether
 * in an action of contract, negligence or other tortious action,
 * arising out of or in connection with the use or performance of
 * this software.
 */

#include <SPI.h>
#include <SRAM_23LC.h>

// SPI bus can be SPI, SPI1 (if present), etc.
#define SPI_PERIPHERAL		SPI
#define CHIP_SELECT_PIN		11

/* Device can be:
 * 128KB: SRAM_23LCV1024, SRAM_23LC1024, SRAM_23A1024
 * 64KB: SRAM_23LCV512, SRAM_23LC512, SRAM_23A512
 * 32KB: SRAM_23A256, SRAM_23K256
 * 8KB: SRAM_23A640, SRAM_23K640
 */
SRAM_23LC SRAM(&SPI_PERIPHERAL, CHIP_SELECT_PIN, SRAM_23K640);

// Additional SRAM chips
// SRAM_23LC SRAM1(&SPI_PERIPHERAL1, CHIP_SELECT_PIN1, SRAM_23LC512);

#define START_ADDRESS   250

//uint8_t buffer[BUFFER_SIZE];
//#define BUFFER_SIZE  320

char buffer[] = "The MattairTech MT-D21E is a development";
#define BUFFER_SIZE  (sizeof(buffer) / sizeof(uint8_t))

void setup(void)
{
  /* Without parameters, begin() uses the default speed for this
   * library (12MHz for samd, 14MHz for sam, and 4MHz for avr).
   * Note that SPI transaction support is required.
   */
  SRAM.begin();
  //SRAM.begin(8000000UL);      // or specify speed

  Serial.begin(9600);
}

void loop(void)
{
  char buffer[] = "The MattairTech MT-D21E is a development";

  while (!Serial); // Wait for serial monitor to connect

  // Print buffer to serial monitor
  Serial.print("Write Block: ");
  for (size_t i=0; i < BUFFER_SIZE; i++) {
    Serial.print(buffer[i]);
  }
  Serial.println();

  // Write block
  if (!SRAM.writeBlock(START_ADDRESS, BUFFER_SIZE, buffer)) {
    Serial.println("Write Block Failure");
  }

  // Clear buffer
  memset(&buffer[0], 0, BUFFER_SIZE);

  // Read Byte, print to serial monitor
  Serial.print("Read Byte:  ");
  for (size_t i=0; i < BUFFER_SIZE; i++) {
    buffer[i] = SRAM.readByte(START_ADDRESS + i);
    Serial.write(buffer[i]);
  }
  Serial.println();

  // Write Byte, print to serial monitor
  Serial.print("Write Byte:  ");
  for (size_t i=0; i < BUFFER_SIZE; i++) {
    Serial.write(buffer[i]);
    SRAM.writeByte(START_ADDRESS + i, buffer[i]);
  }
  Serial.println();

  // Clear buffer
  memset(&buffer[0], 0, BUFFER_SIZE);

  // Read block
  Serial.print("Read Block:  ");
  if (!SRAM.readBlock(START_ADDRESS, BUFFER_SIZE, buffer)) {
    Serial.println("Read Block Failure");
  }

  // Print buffer to serial monitor
  for (size_t i=0; i < BUFFER_SIZE; i++) {
    Serial.write(buffer[i]);
  }
  Serial.println();

  delay(1000);
}

And serial output for it is

Write Block: The MattairTech MT-D21E is a development
Read Byte:
Write Byte:
Read Block:

If this is table data that you only intend to read from, have you thought of storing it in FLASH? You've got 256KB to play with.

If this is table data that you only intend to read from, have you thought of storing it in FLASH? You've got 256KB to play with.

Its just a sample code right now that i am using to check interface with SRAM 23k640, My original code is different and Cant use Flash as it has a limitation of 10000 cycles my waveform will keep reloading in nearly 2 mins so i have to keep flashing 6k every two mins making it cross flash capacity.

Isn't the mega 2560 a 5v device?
wouldn't you need a level shifter between the chip and the mega? (5v mega - 3.3v chip)

Isn't the mega 2560 a 5v device?
wouldn't you need a level shifter between the chip and the mega? (5v mega - 3.3v chip)

I have used atmega2560V with 8Mhz internal crystal(at 8Mhz it supports 3.3V) using Mega core bootloading.

Okay, you can't refresh FLASH anyhow (not easily). How is it not working?

I don't think that SPI should have pullups.

Are you using the correct pins for SPI? the SPI pins on the MEGA are not in the same place as on an Uno.
If you use pin 11 as Chip Select (not the default on MEGA), you may also have to set PIN53 (the actual default SS pin) to an output to force the SPI controller into Master Mode.

westfw:
I don't think that SPI should have pullups.

Beat me to it. I was busy trying to find some evidence for that (I'm not that good with circuitry)
The App note shows pullups only on CS and Hold (Hold wants a cap as well)

Are you using the correct pins for SPI? the SPI pins on the MEGA are not in the same place as on an Uno.
If you use pin 11 as Chip Select (not the default on MEGA), you may also have to set PIN53 (the actual default SS pin) to an output to force the SPI controller into Master Mode.

Made 53 output still no change in output.
Other SPI pins are correct as I was also using a SD card on same pins and it worked ( only ss pin was different.)

I was busy trying to find some evidence for that (I'm not that good with circuitry)
The App note shows pullups only on CS and Hold (Hold wants a cap as well)

I wired hold directly to VCC as i dont want to control it from uC, so dont think it will need that RC.
Does those other pins pullup have any effect.

I removed Other Pull-ups still no change in result! though it isnt showing any Write block failure but it isnt even giving output!

Have you Checked each pin to see if soldering/dry soldering is an issue, or tried a different chip, in case you have a dead one?

Yes just checked there is no dry soldering or wrong connection.
Looks like I have to use 4 channel dso for this project!

hello,
I have checked the waveforms,
The sck is showing clock in burst of 8 square waves,
MOSI is also ok and in synch with sck, Hold is continously pulled up and cs is to ground so it is also as per datasheet.
But I am unable to get any signal on MISO.

Serial.write(buffer[i]);

Shouldn’t you be using Serial.print here and the other places?

Shouldn't you be using Serial.print here and the other places?

it has no effect and serial.Write should also show atleast some random figures but my main problem is I am not getting anything from it.

it has no effect

If a change from Serial.write to Serial.print has NO effect then I have to say I don’t believe you. The two functions treat the data they are given totally differently. If you don’t tell the truth how can anyone help you?

If a change from Serial.write to Serial.print has NO effect then I have to say I don't believe you. The two functions treat the data they are given totally differently. If you don't tell the truth how can anyone help you?

I know that two functions are different one gives ascii code and other one gives readable data. But as I said it has no effect because to make this difference both first need to get some data to print then they can gives either ascii or redable. My basic problem here is I am unable to get the data itself! Sram isnt providing any data thats what I said in given reply.

hello,
I have checked the waveforms,
The sck is showing clock in burst of 8 square waves,
MOSI is also ok and in synch with sck, Hold is continously pulled up and cs is to ground so it is also as per datasheet.
But I am unable to get any signal on MISO.

daily bump...

I have only used the 23K256 and the 23LC104 with a Uno.
The 23K256 has a 16 bit address like the 23K640 so I guess that is the closest.
I did not use a libiary but wrote my own code. This code is for the 23K256 and there is also a MCP4921 D/A converter on the SPI bus as well.
You diagram does not show the pin numbers you used on the Mega so I can't cross check that. Anyway if it is of any use here you are:-

#include <SPI.h>

/*
 D/A test
 D/A on SPI bus, with output fed back to A3 for testing
 MCP 4921 D/A
 ~CS - Pin 9
 SCK - Pin 13 (SCK pin)
 SDI - Pin 11 (MOSI pin)
 LATCH - Pin 8
*/
#define CS_BAR 9
#define LATCH 8
#define ATEST 3
#define SR_CS 10  // static RAM chip select bar
#define SR_SI 12  // serial data input

void setup()
{
  // initilise control pins for A/D
  pinMode(LATCH, OUTPUT);
  digitalWrite(LATCH, HIGH);
  pinMode(CS_BAR, OUTPUT);
  digitalWrite(CS_BAR, HIGH);
    // initilise control pins for SRAM
  pinMode( SR_CS, OUTPUT);
  digitalWrite( SR_CS, HIGH);
  pinMode( SR_SI, INPUT);

  Serial.begin(9600);  // start serial for output
  Serial.println("SRAM test");
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
//  SPI.setDataMode(SPI_MODE3);
  SPI.setDataMode(SPI_MODE0);
  // set status register to byte mode
   digitalWrite( SR_CS,LOW);
  SPI.transfer(0x01);  // write to status register
  SPI.transfer(0x41);  // page mode with hold disabled
  digitalWrite( SR_CS,HIGH); 
  for(int i =0; i<256; i +=2){ // write something to the memory
  ramWrite(i, i << 4);
  }
  SPI.setClockDivider(SPI_CLOCK_DIV2); // maximum clock speed
}

void loop()
{
    for(int i =0; i<256; i +=2){
    //  ramWrite(i, 256-i);
     // ramRead(i); 
      outA_D(ramRead(i)); // read the memory and output it to the D/A
    // printReading(i);
    }
  // delay(1000);
}

int ramRead(int add){ // read val from address as two bytes
int val;
  // digitalWrite( SR_CS,LOW); // pin 10
  PORTB = PINB & 0xfb;
  SPI.transfer(0x03);  // read data from memory instruction
  SPI.transfer(add>>8);
  SPI.transfer(add & 0xff);
  val = SPI.transfer(0) << 8; // read most significant nibble
  val |= SPI.transfer(0);
//  digitalWrite( SR_CS,HIGH); 
  PORTB = PINB | 0x04;
  return val;
}

void ramWrite(int add, int val){ // write val to address add of the SRAM as two bytes
  // digitalWrite( SR_CS,LOW);
   PORTB = PINB & 0xfb;
  SPI.transfer(0x02);  // write data to memory instruction
  SPI.transfer(add>>8);
  SPI.transfer(add & 0xff);
  SPI.transfer(val>>8);  // write MS nibble first
  SPI.transfer(val & 0xff);
 // digitalWrite( SR_CS,HIGH); 
  PORTB = PINB | 0x04; 
}

void outA_D(int value){
  int first;
      first = ( (value >> 8) &0x0f )        |  0x40 |    0x20 |       0x10;
    //                        side A  |bufferd| gain 1 | output enabled
   // take the SS pin low to select the chip:
 // digitalWrite(CS_BAR,LOW); // pin 9
   PORTB = PINB & 0xfd;
  SPI.transfer(first);      //control and MS nibble data
  SPI.transfer(value & 0xff);  // LS byte of data
  //  digitalWrite(CS_BAR,HIGH);
  PORTB = PINB | 0x02; 
 //   digitalWrite(LATCH, LOW);   // latch the output pin 8
 //   digitalWrite(LATCH, HIGH); 
  PORTB = PINB & 0xfe;
  PORTB = PINB | 0x01; 
}
void printReading(int out){
  Serial.print("Output ");
  Serial.print(out);
  Serial.print("  -  Read ");
  Serial.println(analogRead(ATEST));
  delay(80);

}

This is the schematic, note I used some 7407 buffers for the signal level shifting down to 3V3, I didn't see any shifting on your schematic.