You are viewing an older revision! See the latest version
W25X40BV
The is a simple read/write API for the Winbond W25X40BV SPI Flash IC (datasheet).
The W25X40BV IC is one of the few commercially available SPI Flash ICs that comes in DIP packaging, ideal for those hobbyists who want to prototype flash memory without dealing with surface mount devices (SMD). This IC can be purchased from digikey.
This simple API is a derived class of the SPI class from the mbed.h library, meaning that the user can use the public member functions of the SPI class. The SPI communication for the W25X40BV API has the same default format as the SPI class (1MHz, mode 0, 8-bits). It does not utilize the performance benefits of the dual I/O SPI functionality provided by the IC.
You can import the this published library at W25X40BV API.
API¶
Public Member Functions¶

Example usage¶
#include "mbed.h"
#include"W25X40BV.h"
Serial pc(USBTX, USBRX); // tx, rx
int main() {
W25X40BV flash(p5, p6, p7, p8);
pc.printf("SPI init done\n");
// read previously written data at arbitrary address 0x168
char str[11];
flash.readStream(0x168, str, 11);
pc.printf("%s\n",str);
flash.chipErase();
pc.printf("Erase done\n");
// ensure the data has been erased (decimal value 255)
pc.printf("%d\n", flash.readByte(0x00,0x00,0x06));
pc.printf("%d\n", flash.readByte(0x06));
// write character 'a' to arbitrary address 0x0 and 'b' to arbitrary address 0x11
flash.writeByte(0x0, 0x0, 0x06,'a');
flash.writeByte(0x11,'b');
// read characters from previously written locations
pc.printf("%c\n", flash.readByte(0x06));
pc.printf("%c\n", flash.readByte(0x00,0x00,0x06));
pc.printf("%c\n", flash.readByte(0x11));
pc.printf("%c\n", flash.readByte(0x00,0x00,0x11));
// write a stream of characters to arbitrary address 0x168
char string[] = "Hello World";
flash.writeStream(0x168, string, 11);
// read stream from 0x168
char str2[11] = {0};
flash.readStream(0x168, str2, 11);
pc.printf("%s\n",str2);
return 0;
}