Yihui Xiong
/
Seeed_nRF51822_Motion
initial
Embed:
(wiki syntax)
Show/hide line numbers
W25Q16BV.h
00001 // W25Q16BV.h 00002 00003 #ifndef W25Q16BV_H 00004 #define W25Q16BV_H 00005 00006 #include "mbed.h" 00007 //#include "BitBangedSPI.h" 00008 00009 #define SPI_FREQ 1000000 00010 #define SPI_MODE 0 00011 #define SPI_NBIT 8 00012 00013 #define POWERUP_INST 0xAB 00014 #define POWERDOWN_INST 0xB9 00015 #define STATUS1_INST 0x05 00016 #define STATUS2_INST 0x35 00017 #define JDEC_INST 0x9F 00018 #define UNIQUE_INST 0x4B 00019 #define WE_INST 0x06 00020 #define WD_INST 0x04 00021 #define R_INST 0x03 00022 #define W_INST 0x02 00023 #define S_ERASE_INST 0x20 /* 4KB sector erase */ 00024 #define B_ERASE_INST 0xD8 /* 64KB block erase */ 00025 #define C_ERASE_INST 0x60 00026 00027 #define DUMMY_ADDR 0x00 00028 00029 #define WAIT_US_TRES1 5 /* Power Up: 3us */ 00030 //#define WAIT_US_TPUW 10000 /* Power Up Write Time: 1-10ms */ 00031 //#define WAIT_US_TBP 50 /* Byte Program Time: 20-50us */ 00032 //#define WAIT_US_TPP 3000 /* Page Program Time: 0.7-3ms */ 00033 //#define WAIT_US_TSE 400000 /* Sector Erase Time: 30-400ms */ 00034 //#define WAIT_US_TBE 1000000 /* 64KB Block Erase Time: 1000ms */ 00035 //#define WAIT_US_TCE 10000000 /* Chip Erase Time: 3-10s */ 00036 00037 //#define ADDR_BMASK2 0x00ff0000 00038 //#define ADDR_BMASK1 0x0000ff00 00039 //#define ADDR_BMASK0 0x000000ff 00040 00041 //#define ADDR_BSHIFT2 16 00042 //#define ADDR_BSHIFT1 8 00043 //#define ADDR_BSHIFT0 0 00044 00045 #define PAGE_SIZE 256 00046 #define SECTOR_SIZE 4096 00047 #define NUM_SECTORS 512 00048 #define NUM_64KB_BLOCKS 32 00049 00050 #define STATUS_1_BUSY 0x01 00051 00052 class W25Q16BV /*: public BitBangedSPI*/ { 00053 public: 00054 W25Q16BV(PinName mosi, PinName miso, PinName sclk, PinName cs); 00055 00056 int readByte(int addr); // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location 00057 int readByte(int a2, int a1, int a0); // takes the address in 3 separate bytes A[23,16], A[15,8], A[7,0] 00058 void readStream(int addr, char* buf, int count); // takes a 24-bit address, reads count bytes, and stores results in buf 00059 00060 void readJEDEC(uint8_t* manId, uint8_t* memType, uint8_t* cap); 00061 uint8_t readStatus1(); 00062 uint8_t readStatus2(); 00063 00064 void writeByte(int addr, int data); // takes a 24-bit (3 bytes) address and a byte of data to write at that location 00065 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] 00066 void writeStream(int addr, char* buf, int count); // write count bytes of data from buf to memory, starting at addr 00067 00068 void chipErase(); // erase all data on chip 00069 bool blockErase(int startBlock, int num=1); // erase all data in the specified number of 64KB blocks, return false if block number is invalid 00070 bool sectorErase(int startSector, int num=1); // erase all data in the specified number of 4KB sectors, return false if sector number is invalid 00071 00072 void enterDeepPowerDown(); 00073 00074 void exitDeepPowerDown(); 00075 00076 00077 private: 00078 00079 void waitWhileBusy(); 00080 00081 void writeEnable(); // write enable 00082 void writeDisable(); // write disable 00083 void chipEnable(); // chip enable 00084 void chipDisable(); // chip disable 00085 00086 // BitBangedSPI _spi; 00087 SPI _spi; 00088 DigitalOut _cs; 00089 }; 00090 00091 #endif 00092
Generated on Wed Jul 13 2022 20:01:33 by 1.7.2