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.
23LCV1024.cpp@0:937ac9b5da23, 2014-03-18 (annotated)
- Committer:
- chrdoerr
- Date:
- Tue Mar 18 16:33:22 2014 +0000
- Revision:
- 0:937ac9b5da23
23LCV1024 library and test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chrdoerr | 0:937ac9b5da23 | 1 | #include "mbed.h" |
| chrdoerr | 0:937ac9b5da23 | 2 | #include "23LCV1024.h" |
| chrdoerr | 0:937ac9b5da23 | 3 | |
| chrdoerr | 0:937ac9b5da23 | 4 | SRAM23LCV1024::SRAM23LCV1024(SPI& spi, PinName cs) : _spi(spi), _cs(cs) { |
| chrdoerr | 0:937ac9b5da23 | 5 | _cs = 1; // Deselect the device so that it can initialize |
| chrdoerr | 0:937ac9b5da23 | 6 | } |
| chrdoerr | 0:937ac9b5da23 | 7 | |
| chrdoerr | 0:937ac9b5da23 | 8 | int SRAM23LCV1024::getReadMode() { |
| chrdoerr | 0:937ac9b5da23 | 9 | /* The mode bits indicate the operating mode of the SRAM: |
| chrdoerr | 0:937ac9b5da23 | 10 | 00 = Byte mode |
| chrdoerr | 0:937ac9b5da23 | 11 | 10 = Page mode |
| chrdoerr | 0:937ac9b5da23 | 12 | 01 = Sequential mode (default) |
| chrdoerr | 0:937ac9b5da23 | 13 | 11 = Reserved |
| chrdoerr | 0:937ac9b5da23 | 14 | */ |
| chrdoerr | 0:937ac9b5da23 | 15 | |
| chrdoerr | 0:937ac9b5da23 | 16 | _cs = 0; |
| chrdoerr | 0:937ac9b5da23 | 17 | _spi.write(CMD_RDMR); |
| chrdoerr | 0:937ac9b5da23 | 18 | int ram_mode = _spi.write(0)>>6; |
| chrdoerr | 0:937ac9b5da23 | 19 | _cs = 1; |
| chrdoerr | 0:937ac9b5da23 | 20 | |
| chrdoerr | 0:937ac9b5da23 | 21 | return ram_mode; |
| chrdoerr | 0:937ac9b5da23 | 22 | } |
| chrdoerr | 0:937ac9b5da23 | 23 | |
| chrdoerr | 0:937ac9b5da23 | 24 | int SRAM23LCV1024::readBytes(int address, char* buffer, int length) { |
| chrdoerr | 0:937ac9b5da23 | 25 | int i; |
| chrdoerr | 0:937ac9b5da23 | 26 | |
| chrdoerr | 0:937ac9b5da23 | 27 | _cs = 0; |
| chrdoerr | 0:937ac9b5da23 | 28 | _spi.write(CMD_READ); |
| chrdoerr | 0:937ac9b5da23 | 29 | _spi.write((address >> 16) & 0xff); |
| chrdoerr | 0:937ac9b5da23 | 30 | _spi.write((address >> 8) & 0xff); |
| chrdoerr | 0:937ac9b5da23 | 31 | _spi.write(address & 0xff); |
| chrdoerr | 0:937ac9b5da23 | 32 | |
| chrdoerr | 0:937ac9b5da23 | 33 | for (i = 0; i < length; i ++) buffer[i] = _spi.write(0); |
| chrdoerr | 0:937ac9b5da23 | 34 | |
| chrdoerr | 0:937ac9b5da23 | 35 | _cs = 1; |
| chrdoerr | 0:937ac9b5da23 | 36 | return 0; |
| chrdoerr | 0:937ac9b5da23 | 37 | } |
| chrdoerr | 0:937ac9b5da23 | 38 | |
| chrdoerr | 0:937ac9b5da23 | 39 | |
| chrdoerr | 0:937ac9b5da23 | 40 | int SRAM23LCV1024::writeBytes(int address, char* buffer, int length) { |
| chrdoerr | 0:937ac9b5da23 | 41 | int i; |
| chrdoerr | 0:937ac9b5da23 | 42 | |
| chrdoerr | 0:937ac9b5da23 | 43 | _cs = 0; |
| chrdoerr | 0:937ac9b5da23 | 44 | _spi.write(CMD_WRITE); |
| chrdoerr | 0:937ac9b5da23 | 45 | _spi.write((address >> 16) & 0xff); |
| chrdoerr | 0:937ac9b5da23 | 46 | _spi.write((address >> 8) & 0xff); |
| chrdoerr | 0:937ac9b5da23 | 47 | _spi.write(address & 0xff); |
| chrdoerr | 0:937ac9b5da23 | 48 | |
| chrdoerr | 0:937ac9b5da23 | 49 | for (i = 0; i < length; i ++) _spi.write(buffer[i]); |
| chrdoerr | 0:937ac9b5da23 | 50 | |
| chrdoerr | 0:937ac9b5da23 | 51 | _cs = 1; |
| chrdoerr | 0:937ac9b5da23 | 52 | return 0; |
| chrdoerr | 0:937ac9b5da23 | 53 | } |
| chrdoerr | 0:937ac9b5da23 | 54 |