Library to drive the Microchip 23K256 SRAM over SPI.

Dependencies:   mbed

Revision:
2:f96c3c85aa3b
Child:
3:d2314b1ac797
diff -r 28eb43851e6e -r f96c3c85aa3b Ser23K256.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ser23K256.h	Sun Aug 15 13:06:52 2010 +0000
@@ -0,0 +1,37 @@
+// Ser23K256 - drive the Microchip 23K256 SRAM using SPI
+// Copyright (c) 2010 Romilly Cocking
+// Released under the MIT License: http://mbed.org/license/mit
+
+#include "mbed.h"
+
+#ifndef  SER23K256_H
+#define  SER23K256_H
+
+// mode codes for 23K256
+#define BYTE_MODE       0x00
+#define SEQUENTIAL_MODE 0x40
+
+// command codes for 23K256
+#define READ            0x03
+#define WRITE           0x02
+#define READ_STATUS     0x05 // called RDSR in datasheet
+#define WRITE_STATUS    0x01 // called WRSR in datasheet
+
+class Ser23K256 {
+public:
+    Ser23K256(SPI& spi, PinName ncs);
+    char read(int address);
+    void read(int address, char * buffer, int count);
+    void write(int address, char byte);
+    void write(int address, char * buffer, int count);
+private:
+    SPI& _spi;
+    DigitalOut _ncs;
+    char readStatus();
+    void writeStatus(char status);
+    void prepareCommand(char command, int address);
+    void select();
+    void deselect();
+};
+
+#endif