I had a need in a project for a fast easy external memory.
Microchip's 23K256 is ideal.
I looked at Spi Library and Spi RAM Library from the arduino playground.
What I really wanted was to have the ram accessible continually from my code.
I did not want to pass address and length each time I stored or retrieved data.
My class has four functions:
writestream: Setup the SRAM in sequential write mode starting from the passed address.
Data can then be written one byte at a time using RWdata(byte data).
Each byte is stored in the next location and it wraps around 32767.
readstream: Setup the SRAM in sequential read mode starting from the passed address.
Data can then be read one byte at a time using byte RWdata(0).The passed data is irrelavent.
Each byte is read from the next location and it wraps around 32767.
RWdata: Write or read the data from the SRAM.
If the writesteam is open the passed data will be written to the current address.
If the readstream is open the data from the current address will be returned.
closeRWstream: Use to close the open read or write stream.
Dont need when changing between read/write.
Close before using SPI somewhere else.
digital pin 13 SCK
digital pin 12 MISO
digital pin 11 MOSI
digital pin 10 SS
I want it for blocks of data, but it can still be used for individual bytes.
This is the example RWbyte you will find in the library:
#include <SRAM.h>
void setup()
{
Serial.begin(9600); // initialize serial communications
}//end of setupvoid loop()
{
SRAM.writestream(22767); //open writestream address from 0 to 32767SRAM.RWdata(75); //the byte to write to SRAM at current address
SRAM.readstream(22767); //open readstream address from 0 to 32767
int data = SRAM.RWdata(0xff); //read byte from SRAM at current address
Serial.println(data); //check data
delay(1000);
}//end of loop
This example to write and read all 32768 bytes is in the library:
#include <SRAM.h>
void setup()
{
Serial.begin(9600); // initialize serial communications
}//end of setupvoid loop()
{
SRAM.writestream(0); // start address from 0unsigned long stopwatch = millis(); //start stopwatch
for(unsigned int i = 0; i < 32768; i++)
SRAM.RWdata(0x55); //write to every SRAM addressSerial.print(millis() - stopwatch);
Serial.println(" ms to write full SRAM");SRAM.readstream(0); // start address from 0
for(unsigned int i = 0; i < 32768; i++)
{
if(SRAM.RWdata(0xFF) != 0x55) //check every address in the SRAM
{
Serial.println("error in location ");
Serial.println(i);
break;
}//end of print error
if(i == 32767)
Serial.println("no errors in the 32768 bytes");
}//end of get bytedelay(1000);
}//end of loop
If it all works you should see:
116 ms to write full SRAM
no errors in the 32768 bytes
For the library and circuit download SRAMclass.zip from: