Romilly Cocking
/
Ser23K256
Library to drive the Microchip 23K256 SRAM over SPI.
Ser23K256.h@2:f96c3c85aa3b, 2010-08-15 (annotated)
- Committer:
- romilly
- Date:
- Sun Aug 15 13:06:52 2010 +0000
- Revision:
- 2:f96c3c85aa3b
- Child:
- 3:d2314b1ac797
created a library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
romilly | 2:f96c3c85aa3b | 1 | // Ser23K256 - drive the Microchip 23K256 SRAM using SPI |
romilly | 2:f96c3c85aa3b | 2 | // Copyright (c) 2010 Romilly Cocking |
romilly | 2:f96c3c85aa3b | 3 | // Released under the MIT License: http://mbed.org/license/mit |
romilly | 2:f96c3c85aa3b | 4 | |
romilly | 2:f96c3c85aa3b | 5 | #include "mbed.h" |
romilly | 2:f96c3c85aa3b | 6 | |
romilly | 2:f96c3c85aa3b | 7 | #ifndef SER23K256_H |
romilly | 2:f96c3c85aa3b | 8 | #define SER23K256_H |
romilly | 2:f96c3c85aa3b | 9 | |
romilly | 2:f96c3c85aa3b | 10 | // mode codes for 23K256 |
romilly | 2:f96c3c85aa3b | 11 | #define BYTE_MODE 0x00 |
romilly | 2:f96c3c85aa3b | 12 | #define SEQUENTIAL_MODE 0x40 |
romilly | 2:f96c3c85aa3b | 13 | |
romilly | 2:f96c3c85aa3b | 14 | // command codes for 23K256 |
romilly | 2:f96c3c85aa3b | 15 | #define READ 0x03 |
romilly | 2:f96c3c85aa3b | 16 | #define WRITE 0x02 |
romilly | 2:f96c3c85aa3b | 17 | #define READ_STATUS 0x05 // called RDSR in datasheet |
romilly | 2:f96c3c85aa3b | 18 | #define WRITE_STATUS 0x01 // called WRSR in datasheet |
romilly | 2:f96c3c85aa3b | 19 | |
romilly | 2:f96c3c85aa3b | 20 | class Ser23K256 { |
romilly | 2:f96c3c85aa3b | 21 | public: |
romilly | 2:f96c3c85aa3b | 22 | Ser23K256(SPI& spi, PinName ncs); |
romilly | 2:f96c3c85aa3b | 23 | char read(int address); |
romilly | 2:f96c3c85aa3b | 24 | void read(int address, char * buffer, int count); |
romilly | 2:f96c3c85aa3b | 25 | void write(int address, char byte); |
romilly | 2:f96c3c85aa3b | 26 | void write(int address, char * buffer, int count); |
romilly | 2:f96c3c85aa3b | 27 | private: |
romilly | 2:f96c3c85aa3b | 28 | SPI& _spi; |
romilly | 2:f96c3c85aa3b | 29 | DigitalOut _ncs; |
romilly | 2:f96c3c85aa3b | 30 | char readStatus(); |
romilly | 2:f96c3c85aa3b | 31 | void writeStatus(char status); |
romilly | 2:f96c3c85aa3b | 32 | void prepareCommand(char command, int address); |
romilly | 2:f96c3c85aa3b | 33 | void select(); |
romilly | 2:f96c3c85aa3b | 34 | void deselect(); |
romilly | 2:f96c3c85aa3b | 35 | }; |
romilly | 2:f96c3c85aa3b | 36 | |
romilly | 2:f96c3c85aa3b | 37 | #endif |