Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: 23LCV1024.cpp
- Revision:
- 0:937ac9b5da23
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/23LCV1024.cpp Tue Mar 18 16:33:22 2014 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#include "23LCV1024.h"
+
+SRAM23LCV1024::SRAM23LCV1024(SPI& spi, PinName cs) : _spi(spi), _cs(cs) {
+ _cs = 1; // Deselect the device so that it can initialize
+}
+
+int SRAM23LCV1024::getReadMode() {
+ /* The mode bits indicate the operating mode of the SRAM:
+ 00 = Byte mode
+ 10 = Page mode
+ 01 = Sequential mode (default)
+ 11 = Reserved
+ */
+
+ _cs = 0;
+ _spi.write(CMD_RDMR);
+ int ram_mode = _spi.write(0)>>6;
+ _cs = 1;
+
+ return ram_mode;
+}
+
+int SRAM23LCV1024::readBytes(int address, char* buffer, int length) {
+ int i;
+
+ _cs = 0;
+ _spi.write(CMD_READ);
+ _spi.write((address >> 16) & 0xff);
+ _spi.write((address >> 8) & 0xff);
+ _spi.write(address & 0xff);
+
+ for (i = 0; i < length; i ++) buffer[i] = _spi.write(0);
+
+ _cs = 1;
+ return 0;
+}
+
+
+int SRAM23LCV1024::writeBytes(int address, char* buffer, int length) {
+ int i;
+
+ _cs = 0;
+ _spi.write(CMD_WRITE);
+ _spi.write((address >> 16) & 0xff);
+ _spi.write((address >> 8) & 0xff);
+ _spi.write(address & 0xff);
+
+ for (i = 0; i < length; i ++) _spi.write(buffer[i]);
+
+ _cs = 1;
+ return 0;
+}
+
\ No newline at end of file