Winbond W25Q80BV SPI library
W25Q80BV.h@3:efef6d4c6918, 2014-01-31 (annotated)
- Committer:
- perezalvarezhi
- Date:
- Fri Jan 31 00:24:52 2014 +0000
- Revision:
- 3:efef6d4c6918
- Parent:
- 2:e8dc659cf54e
publishing new library and deleting old falash library;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
perezalvarezhi | 0:6f374c3ed666 | 1 | // W25Q80BV.h |
perezalvarezhi | 0:6f374c3ed666 | 2 | |
perezalvarezhi | 0:6f374c3ed666 | 3 | #ifndef W25Q80BV_H |
perezalvarezhi | 0:6f374c3ed666 | 4 | #define W25Q80BV_H |
perezalvarezhi | 0:6f374c3ed666 | 5 | |
perezalvarezhi | 0:6f374c3ed666 | 6 | #include "mbed.h" |
perezalvarezhi | 0:6f374c3ed666 | 7 | |
perezalvarezhi | 0:6f374c3ed666 | 8 | #define SPI_FREQ 1000000 |
perezalvarezhi | 0:6f374c3ed666 | 9 | #define SPI_MODE 0 |
perezalvarezhi | 0:6f374c3ed666 | 10 | #define SPI_NBIT 8 |
perezalvarezhi | 0:6f374c3ed666 | 11 | |
perezalvarezhi | 2:e8dc659cf54e | 12 | #define WRITE_ENABLE 0x06 |
perezalvarezhi | 2:e8dc659cf54e | 13 | #define WRITE_DISABLE 0x04 |
perezalvarezhi | 2:e8dc659cf54e | 14 | #define READ_DATA 0x03 |
perezalvarezhi | 2:e8dc659cf54e | 15 | #define WRITE_DATA 0x02 |
perezalvarezhi | 2:e8dc659cf54e | 16 | #define CHIP_ERASE 0x60 |
perezalvarezhi | 2:e8dc659cf54e | 17 | #define DEV_ID 0x90 |
perezalvarezhi | 0:6f374c3ed666 | 18 | |
perezalvarezhi | 0:6f374c3ed666 | 19 | #define DUMMY_ADDR 0x00 |
perezalvarezhi | 0:6f374c3ed666 | 20 | #define WAIT_TIME 1 |
perezalvarezhi | 0:6f374c3ed666 | 21 | |
perezalvarezhi | 0:6f374c3ed666 | 22 | #define ADDR_BMASK2 0x00ff0000 |
perezalvarezhi | 0:6f374c3ed666 | 23 | #define ADDR_BMASK1 0x0000ff00 |
perezalvarezhi | 0:6f374c3ed666 | 24 | #define ADDR_BMASK0 0x000000ff |
perezalvarezhi | 0:6f374c3ed666 | 25 | |
perezalvarezhi | 0:6f374c3ed666 | 26 | #define ADDR_BSHIFT2 16 |
perezalvarezhi | 0:6f374c3ed666 | 27 | #define ADDR_BSHIFT1 8 |
perezalvarezhi | 0:6f374c3ed666 | 28 | #define ADDR_BSHIFT0 0 |
perezalvarezhi | 0:6f374c3ed666 | 29 | |
perezalvarezhi | 0:6f374c3ed666 | 30 | class W25Q80BV { |
perezalvarezhi | 0:6f374c3ed666 | 31 | public: |
perezalvarezhi | 0:6f374c3ed666 | 32 | W25Q80BV(PinName mosi, PinName miso, PinName sclk, PinName cs); |
perezalvarezhi | 0:6f374c3ed666 | 33 | int readByte(int addr); // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location |
perezalvarezhi | 0:6f374c3ed666 | 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] |
perezalvarezhi | 0:6f374c3ed666 | 35 | void readStream(int addr, char* buf, int count); // takes a 24-bit address, reads count bytes, and stores results in buf |
perezalvarezhi | 0:6f374c3ed666 | 36 | |
perezalvarezhi | 0:6f374c3ed666 | 37 | void writeByte(int addr, int data); // takes a 24-bit (3 bytes) address and a byte of data to write at that location |
perezalvarezhi | 0:6f374c3ed666 | 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] |
perezalvarezhi | 0:6f374c3ed666 | 39 | void writeStream(int addr, char* buf, int count); // write count bytes of data from buf to memory, starting at addr |
perezalvarezhi | 0:6f374c3ed666 | 40 | |
perezalvarezhi | 0:6f374c3ed666 | 41 | void chipErase(); // erase all data on chip |
perezalvarezhi | 0:6f374c3ed666 | 42 | int getMID( ) ; //Get the manufacturer ID |
perezalvarezhi | 0:6f374c3ed666 | 43 | |
perezalvarezhi | 0:6f374c3ed666 | 44 | private: |
perezalvarezhi | 0:6f374c3ed666 | 45 | void writeEnable(); // write enable |
perezalvarezhi | 0:6f374c3ed666 | 46 | void writeDisable(); // write disable |
perezalvarezhi | 0:6f374c3ed666 | 47 | void chipEnable(); // chip enable |
perezalvarezhi | 0:6f374c3ed666 | 48 | void chipDisable(); // chip disable |
perezalvarezhi | 0:6f374c3ed666 | 49 | int writeSPI(int data); //software Spi write |
perezalvarezhi | 0:6f374c3ed666 | 50 | |
perezalvarezhi | 0:6f374c3ed666 | 51 | // SPI inputs/outpus; |
perezalvarezhi | 0:6f374c3ed666 | 52 | DigitalOut _cs; |
perezalvarezhi | 0:6f374c3ed666 | 53 | DigitalOut _mosi; |
perezalvarezhi | 0:6f374c3ed666 | 54 | DigitalIn _miso; |
perezalvarezhi | 0:6f374c3ed666 | 55 | DigitalOut _sclk; |
perezalvarezhi | 0:6f374c3ed666 | 56 | }; |
perezalvarezhi | 0:6f374c3ed666 | 57 | |
perezalvarezhi | 0:6f374c3ed666 | 58 | #endif |