Winbond W25Q80BV SPI library

Dependents:   data_log

Committer:
perezalvarezhi
Date:
Wed Jan 29 02:05:38 2014 +0000
Revision:
0:6f374c3ed666
Child:
2:e8dc659cf54e
Primer intento de SPI, funcion writebyte de SPI; ;

Who changed what in which revision?

UserRevisionLine numberNew 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 0:6f374c3ed666 12 #define WE_INST 0x06
perezalvarezhi 0:6f374c3ed666 13 #define WD_INST 0x04
perezalvarezhi 0:6f374c3ed666 14 #define R_INST 0x03
perezalvarezhi 0:6f374c3ed666 15 #define W_INST 0x02
perezalvarezhi 0:6f374c3ed666 16 #define C_ERASE_INST 0x60
perezalvarezhi 0:6f374c3ed666 17 #define D_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