Page reading in srams

I have been trying to get the page mode r/w operations to work on my 23lc1024 SRAMs, but I just can't seem to get the syntax correct.

I had first wrote the program similar to how you would write a C program to read and write 32 byte data array, but I found out later that it doesn't actually read the memory as such, and that you had to use certain inbuilt arduino syntax. I would appreciate any help I can get on my following code:

/*
Used the following components:
(1) Arduino Uno
(2) Microchip 23LC51024

ORIGINAL Code by Jim Eli
*/

#include <SPI.h>

//SRAM opcodes
#define RDSR 5
#define WRSR 1
#define READ 3
#define WRITE 2

//i can define these in the setup function below
byte cs_pin[2] = {10, 9};

uint32_t maxpage = 4096;

/------------------------------------------------------------------------------------------------------------------------/
//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* buffer)
{
uint32_t i; //important to be local or else the loop in loop function doesnt work
uint8_t read_page;

digitalWrite(cs_pin, LOW); //PORTB &= ~(1<<PORTB2); //set SPI_SS low
SPI.transfer(READ);
SPI.transfer((uint8_t)(address >> 16) & 0xff);
SPI.transfer((uint8_t)(address >> 8) & 0xff); //shift our address 24 bits to the right to make way for each address. if using 23k256 or 23lcv512 microchips you only shift 16.

SPI.transfer((uint8_t)address);

for (i = 0; i < 32; i++)
{
read_page = SPI.transfer(0x00);
}
digitalWrite(cs_pin, HIGH); //PORTB |= (1<<PORTB2); //set SPI_SS high

//Serial.println(read_page); //explore this function in more detail
}

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

digitalWrite(cs_pin, LOW); //PORTB &= ~(1<<PORTB2);
SPI.transfer(WRITE);
SPI.transfer((uint8_t)(address >> 16) & 0xff);
SPI.transfer((uint8_t)(address >> 8) & 0xff);

SPI.transfer((uint8_t)address);

for (i = 0; i < 32; i++)
{
SPI.transfer(buffer170*);*

  • }*

  • digitalWrite(cs_pin, HIGH); //PORTB |= (1<<PORTB2);*
    }
    _/-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-/ _
    //stream transfer functions.
    //here you can read and write as many bytes as you want at each address.
    /-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-/
    uint32_t i, j, n; //loop iterative values
    uint32_t value;
    uint32_t num = 0; //for cumulative error counts
    //the important 32 element buffer array to be used in page mode
    uint8_t buffer170[32] = {170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170};
    uint8_t set_value = 170;
    void setup(void)
    {

  • Serial.begin(115200);*

  • SPI.begin();*

  • SPI.setClockDivider(SPI_CLOCK_DIV32); //you can play around with different SPI clock times here. Very slow communicating to Serial Monitor when its uncommented*

  • //Set all pins to high, and then call low when communicating*

  • pinMode(10, OUTPUT);*

  • digitalWrite(10, HIGH);*

  • pinMode(9, OUTPUT);*

  • digitalWrite(9, HIGH);*

}

void loop()
{
_ /----THIS IS TO READ ALL PAGES IN THE TWO SRAMS ONE AT A TIME----/_

  • for (j = 0; j < 2; j++)*
  • {*
  • num = 0;*
  • for (i = 0; i < maxpage; i++)*
  • {*
  • Spi23LC1024Write32(i, buffer170, cs_pin[j]);*
  • }*
  • //Serial.println(maxpage); //to check its looped through all 4096 pages*
  • for (i = 0; i < maxpage; i++)*
  • {*
  • Spi23LC1024Read32(i, cs_pin[j]);*
  • for (n = 0; n < 32; n++) //because each page consists of a further 32 bytes, here we will check all 32 array elements to see if it matches 170.*
  • {*
  • if (buffer170[n] != set_value)*
  • {*
  • //Serial.print("BITFLIP: ");*
  • //Serial.print(value, HEX);*
  • //Serial.print(" at: ");*
  • //Serial.print(n);*
  • //Serial.print(";");*
  • //Serial.println(i);*
  • num++;*
  • }*
  • }*
  • }*
  • Serial.println(num); //How many errors occured in this cs_line/SRAM*
  • delay(3000);*
  • }*
    }
    I appreciate this, Thank you