W25X40BV

Table of Contents

  1. Connectivity
  2. API

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.

Connectivity

mbedW25X40BV
p40 (Vout 3.3V)p8 (3.3V VCC)
p40 (Vout 3.3V)p3 (/WP)
p40 (Vout 3.3V)p7 (/HOLD)
p5 (mosi)p5 (DI)
p6 (miso)p2 (DO)
p7 (sck)p6 (CLK)
p8 (GPO)p1 (/CS)

Note that the write protect and hold are both active LOW; thus, to disable their functionality, set them to HIGH (3.3V). Using addition GPO (DigitalOut) pins from the mbed is an alternative to connecting the W25X40BV /WP and /HOLD directly to VCC (Vout from the mbed).

API

Import libraryW25X40BV

Simple read/write API for the W25X40BV SPI Flash IC wiki: http://mbed.org/cookbook/W25X40BV

Public Member Functions

/media/uploads/jyam/windbond_spi_flash_api.png

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;
}



All wikipages