[ FORK ] SPI flash memory control library forked from jyam/W25X40BV
Dependents: 11u35_usbLocalFilesystem
Fork of W25X40BV by
W25X40BV.h@1:cd41b8e3fdad, 2012-03-19 (annotated)
- Committer:
- jyam
- Date:
- Mon Mar 19 14:55:24 2012 +0000
- Revision:
- 1:cd41b8e3fdad
- Parent:
- 0:9de212faf980
- Child:
- 2:2b0daec9f8c0
added sequential read and write
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jyam | 1:cd41b8e3fdad | 1 | // W25X40BV.h |
jyam | 1:cd41b8e3fdad | 2 | |
jyam | 1:cd41b8e3fdad | 3 | #ifndef W25X40BV_H |
jyam | 1:cd41b8e3fdad | 4 | #define W25X40BV_H |
jyam | 1:cd41b8e3fdad | 5 | |
jyam | 1:cd41b8e3fdad | 6 | #include "mbed.h" |
jyam | 1:cd41b8e3fdad | 7 | |
jyam | 1:cd41b8e3fdad | 8 | #define SPI_FREQ 1000000 |
jyam | 1:cd41b8e3fdad | 9 | #define SPI_MODE 0 |
jyam | 1:cd41b8e3fdad | 10 | #define SPI_NBIT 8 |
jyam | 1:cd41b8e3fdad | 11 | |
jyam | 1:cd41b8e3fdad | 12 | #define WE_INST 0x06 |
jyam | 1:cd41b8e3fdad | 13 | #define WD_INST 0x04 |
jyam | 1:cd41b8e3fdad | 14 | #define R_INST 0x03 |
jyam | 1:cd41b8e3fdad | 15 | #define W_INST 0x02 |
jyam | 1:cd41b8e3fdad | 16 | #define C_ERASE_INST 0x60 |
jyam | 1:cd41b8e3fdad | 17 | |
jyam | 1:cd41b8e3fdad | 18 | #define DUMMY_ADDR 0x00 |
jyam | 1:cd41b8e3fdad | 19 | #define WAIT_TIME 1 |
jyam | 1:cd41b8e3fdad | 20 | |
jyam | 1:cd41b8e3fdad | 21 | #define ADDR_BMASK2 0x00ff0000 |
jyam | 1:cd41b8e3fdad | 22 | #define ADDR_BMASK1 0x0000ff00 |
jyam | 1:cd41b8e3fdad | 23 | #define ADDR_BMASK0 0x000000ff |
jyam | 1:cd41b8e3fdad | 24 | |
jyam | 1:cd41b8e3fdad | 25 | #define ADDR_BSHIFT2 16 |
jyam | 1:cd41b8e3fdad | 26 | #define ADDR_BSHIFT1 8 |
jyam | 1:cd41b8e3fdad | 27 | #define ADDR_BSHIFT0 0 |
jyam | 1:cd41b8e3fdad | 28 | |
jyam | 1:cd41b8e3fdad | 29 | class W25X40BV { |
jyam | 1:cd41b8e3fdad | 30 | public: |
jyam | 1:cd41b8e3fdad | 31 | W25X40BV(PinName mosi, PinName miso, PinName sclk, PinName cs); |
jyam | 1:cd41b8e3fdad | 32 | |
jyam | 1:cd41b8e3fdad | 33 | int readByte(int addr); // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location |
jyam | 1:cd41b8e3fdad | 34 | int readByte(int a2, int a1, int a0); // takes the address in 3 separate bytes A[23,16], A[15,8], A[7,0] |
jyam | 1:cd41b8e3fdad | 35 | void read(int addr, char* buf, int count); // takes a 24-but address, reads count bytes, and stores results in buf |
jyam | 1:cd41b8e3fdad | 36 | |
jyam | 1:cd41b8e3fdad | 37 | void writeByte(int addr, int data); // takes a 24-bit (3 bytes) address and a byte of data to write at that location |
jyam | 1:cd41b8e3fdad | 38 | void writeByte(int a2, int a1, int a0, int data); // takes the address in 3 separate bytes A[23,16], A[15,8], A[7,0] |
jyam | 1:cd41b8e3fdad | 39 | void write(int addr, char* buf, int count); // write count bytes of data from buf to memory, starting at addr |
jyam | 1:cd41b8e3fdad | 40 | |
jyam | 1:cd41b8e3fdad | 41 | void chipErase(); // erase all data on chip |
jyam | 1:cd41b8e3fdad | 42 | |
jyam | 1:cd41b8e3fdad | 43 | private: |
jyam | 1:cd41b8e3fdad | 44 | void writeEnable(); // write enable |
jyam | 1:cd41b8e3fdad | 45 | void writeDisable(); // write disable |
jyam | 1:cd41b8e3fdad | 46 | void chipEnable(); // chip enable |
jyam | 1:cd41b8e3fdad | 47 | void chipDisable(); // chip disable |
jyam | 1:cd41b8e3fdad | 48 | |
jyam | 1:cd41b8e3fdad | 49 | SPI _spi; |
jyam | 1:cd41b8e3fdad | 50 | DigitalOut _cs; |
jyam | 1:cd41b8e3fdad | 51 | }; |
jyam | 1:cd41b8e3fdad | 52 | |
jyam | 0:9de212faf980 | 53 | #endif |