1

I'm trying to reset SRAM 23LC1024 (Turn it off and turn it on again) connected to my Arduino Mega 2560. I need to do that because I want to profile the SRAM in an attempt to implement PUF. Currently, I'm able to read and write to SRAM.

I try to cut off the ground connected to SRAM, disable the SPI, but the memory in SRAM is not back to random value (initial value of SRAM if you reset it correctly). To disconnect or connect the ground with SRAM, I used MOSFET. Before cut off the ground, I write 1's to all memory. But, after wait for seconds (or minutes), the value still the same.

Now, the only way to reset the SRAM that I know is by resetting the Arduino itself. Can someone help me?

Below is my code

#include <SPI.h>

//SRAM opcodes

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

byte cs_pin = 10; //cs_pin location of the two SRAMS

//uint32_t maxram = 131072; //number of bytes in 23LC1024 SRAM
uint32_t maxpage = 4096;  //number of pages in 23LC1024 SRAM
//uint32_t maxpage = 1024;  //number of pages in 23K256 SRAM

/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-*/
//Page transfer Functions
//here we can read and write 32 bytes at each address

void Spi23LC1024Read32(uint32_t address, uint8_t cs_pin, uint8_t* buff)
{
  uint32_t i; 
  uint8_t read_page; 

  digitalWrite(cs_pin, LOW);  
  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16));
  SPI.transfer((uint8_t)(address >> 8)); 
  SPI.transfer((uint8_t)address);

  for (i = 0; i < 32; i++)
  {
      read_page = SPI.transfer(0x00);
      buff[i] = read_page;
  }
  digitalWrite(cs_pin, HIGH);   
}

void Spi23LC1024Write32(uint32_t address, uint8_t buffer170, uint8_t cs_pin)
{
    uint32_t i;

    digitalWrite(cs_pin, LOW); 
    SPI.transfer(WRITE);
    SPI.transfer((uint8_t)(address >> 16));
    SPI.transfer((uint8_t)(address >> 8));
    SPI.transfer((uint8_t)address);

    for (i = 0; i < 32; i++)
    {
        SPI.transfer(buffer170);
    }
    digitalWrite(cs_pin, HIGH); 
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-*/

uint32_t i, j, n; 
uint32_t value; 
uint32_t num = 0; 
uint32_t total_send = 10; 
uint8_t buff[32];
uint32_t index = 0;
uint8_t total_buff[32*128];
int inByte;

int pin_hold = 11;
int pin_select = 10;
int pin_mosfet = 12;

void readSRAM(){
  SPI.begin();
  digitalWrite(pin_select, LOW);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, HIGH);
  delay(100);

// read
  for (j = 0; j < maxpage/128; j++){
    index = 0;
    for (i = 0; i < 128; i++) 
    {
      Spi23LC1024Read32(j*128+i, cs_pin,buff);
      memcpy(&total_buff[index], buff, sizeof(buff));
      index += 32;
    }

    for (i = 0; i< index; i++){
      Serial.println(total_buff[i], HEX);
    }
  }

   digitalWrite(pin_select, HIGH);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, LOW);

  SPI.end();
}

void writeSRAM(){
  SPI.begin();
  digitalWrite(pin_select, LOW);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, HIGH);
  delay(100);

// write
  for (j = 0; j < maxpage/128; j++){
    index = 0;
    for (i = 0; i < 128; i++) 
    {
      Spi23LC1024Write32(j*128+i, (uint8_t) 0, cs_pin);
    }
  }

  digitalWrite(pin_select, HIGH);
  digitalWrite(pin_hold, HIGH);
  digitalWrite(pin_mosfet, LOW);

  SPI.end();
}

void set(){
  Serial.begin(115200);

  delay(100);

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(pin_select, OUTPUT);
  pinMode(pin_hold, OUTPUT);
  pinMode(pin_mosfet, OUTPUT);
}

void setup(void) 
{
  set();

  readSRAM();

  writeSRAM();
}

void loop() 
{
}
  • Rather than cutting the ground, couldn't you connect the chip's Vcc to a digital pin on the Mega? Set the pin to LOW when you want to turn the chip off, and back to HIGH when you want to turn it on? – dda Nov 22 '17 at 3:23
  • @dda i've also tried that, but still doesn't reset the SRAM value. – asajim Nov 22 '17 at 13:36
  • I had a look at the datasheet, and I don't see anything specific that needs to be done to reset the chip (like send a function to tell the chip "scramble your brains!"). So I'm wondering whether adding a delay before turning it on again isn't necessary. Have you tried playing with delays? – dda Nov 23 '17 at 0:45
  • @dda yup, doesn't matter how long is the delays, it still stuck in the same value. for example, i try using 60 seconds as the delay, but the memory value is still similar. – asajim Nov 23 '17 at 7:23
  • 4
    I'm voting to close this question as off-topic because it has nothing to do with Arduino but is rather an X-Y problem arising from severe and fundamental misunderstanding of static RAM, IC absolute maximum ratings, and the meaning of the term "reset" – Chris Stratton Dec 29 '17 at 3:44
0

As an experiment I would make sure ALL the pins are at 0V for reset. Power on ANY pin with a return path may provide enough parasitic power to prevent a proper shutdown.

As has been pointed out you can use a I/O pin to power the device. This SRAM has 10mA operating current; enough to be supplied by an I/O pin. Then, with code only, you can make sure all pins go to 0V for the reset. This will also give you an extra power saving mode for free.

Not the answer you're looking for? Browse other questions tagged or ask your own question.