SPIMemory library - Formerly SPIFlash - now supports SPI FRAM as well! :)

Is the Arduino Nano known to not work, or is it a matter of testing?

@liolau: The Nano is just a matter of testing. It uses the same ATMega328 µC as in the Uno so it should work with no issues.

Hi all, just pushed through a major bug-fix release v3.0.1

@hanyazou identified a major bug (detailed here in issue 102) which has been fixed with v3.0.1

v3.0.1 also adds support for the S25FL127S from Spansion/Cypress.

As always, you can find this version on Github here --> SPIFlash Library for Arduino v3.0.1 A ZIP file is also attached to the first post on this thread. The easiest way, as always, is to open up Library Manager on your Arduino IDE and update the library to v3.0.1 :)


Does this library support QSPI ? I have wired W25Q128JV in QSPI mode and was wondering if I could try that with this llibrary

I get some error on save to flash. flash.writeAnything with char variables in struct fails.

I have two structs

struct Configuration {
  uint8_t tempHigh;         // store higher value for temperature
  uint8_t tempLow;          // store lower value for temperature
  bool parkingMode;         // store Parking Battery value boolean
  uint8_t chargingRange;    // store charging range status
  uint8_t chargingHigh;     // store charging higher value
  uint8_t chargingLow;      // store charging lower value
  boolean sendData;         // store send data flag
} configuration;

struct NetworkConfig {
  char ssid[50];            // Store network ssid from client
  char pwd[50];             // Store network password from client
  char userid[50];          // Store identification ID from client
} networkConfig;

set some values on both struct, and save to flash:

  if (flash.writeAnything(0, configuration)) {
    Serial.println ("Data write successful");
  } else {
    Serial.println ("Data write failed");

  if (flash.writeAnything(1, networkConfig)) {
    Serial.println ("Data write successful");
  } else {
    Serial.println ("Data write failed");
  flash.readAnything(0, configuration);
  flash.readAnything(1, networkConfig);


Serial Monitor:

Data write successful
Data write failed

All the values from struct “configuration” are OK.
Some has an Idea please.

after changing struct to nested struct, all is good.

Hi - thanks for a fantastic library! I know this is a pretty big ask but maybe someone here can help out. I’d love to use this library on an STM32 MCU in the Particle ecosystem. Particle is a fork of Arduino/Wiring, in my understanding, so I don’t think a ton would need to change but it’s hard to tell. Has anyone tried this or perhaps have any advice for where I could start? Thank you!

is there a conflict between EEPROM (mega2560 internal flash) and SPIFLASH Lib?
I tried to adjust the bootloader, then I noticed that the data on the winbond is gone, and the bootloader is not working as expected.

I tried this one.

Any idea?

@a7ashh14: I'm afraid it does not yet support QSPI. What µC are you using with your W25Q128JV?

@supscientist: I've yet to play around with the Particle/Electron ecosystem. Feel free to play around with the code in the 'stable' branch of the library on Github and see if you can make it compatible with the Particle ecosystem. :)

@mysource: What pins are you connecting your Flash memory to? I don't think that the conflict is between the EEPROM and the Flash - its the probably because you use the SPI bus to program your Mega. If somehow, during the programming the Slave Select pin (that you have your flash connected to) is a) pulled low or b) the voltage drops and the µC enters Brown-out mode - then the data that's being sent into your Mega might a) get piped into your Flash memory as well or b) be interrupted unexpectedly. This could very easily cause corruption of the data on both the Mega's internal flash and the external SPI Flash you are using.

@supscientist As a place to start, take a look at how Particle’s SPI Library works and see how you can replace the calls to the Arduino SPI Library with calls to the Particle SPI Library in FLASHIO.cpp. Every function in SPIFlash is built on top of the private functions in FLASHIO.cpp that make calls to the SPI Library - so the majority of your work should be done with this step. You might also have to modify some defines in defines.h.

Hi Marzogh,

Thanks for creating SPIFlash -- I can see a tremendous amount of work has gone into it.

I am new to SPI Flash memory so I may be asking a stupid question but here goes. My basic question is: does SPIFlash support the "JV" series of chips from Winbond, specifically the W25Q32JVSSIQ and W25Q64JVSSIQ? Or is there something about the JV series that makes them incompatible, and I should try to find the BV of FV series mentioned in the wiki?

The details:

I got some Winbond chips from DigiKey: W25Q32JVSSIQ and W25Q64JVSSIQ. I soldered them on some SMT breakout boards from Adafruit and wired them up to an Adafruit Feather M0. The pinouts are:

3V --> 8 (VCC) GND --> 4 (GND) SCK --> 6 (CLK) MOSI --> 5 (DI / IO0) MISO --> 2 (DO / IO1) GPIO #11 --> 1 (/CS)

At first, I did not hook up pins 3 (IO2) or 7 (IO3) to anything since it seemed they were not needed in this configuration.

I modified the readWriteString example sketch to tell it to use pin 11 for chip select in the SPIFlash constructor:

//SPIFlash flash;
SPIFlash flash(11);

However, when I run I get an endless stream of this error message:

Unable to Enable Writing to chip.
Please make sure the HOLD & WRITEPROTECT pins are pulled up to VCC

According to the Winbond data sheet, the JV series of chips do not have HOLD and WRITEPROTECT pins:


Unlike the FV series, which state that pin 3 is both /WP and IO2, and pin 7 is both HOLD and IO3, the JV series just calls them IO2 and IO3. Looks like write protection is enabled/disabled only via the status registers.

I tried various combinations of tying pins 3 and/or 7 to Vdd and Vcc, but always got the same error. Then, based on the error message, I tried putting pullup resistors between 3 and 7 and Vcc, with values of 5.1K and then 100K, but I admit I'm just guessing there. Same result.

So ... am I out of luck? Is this chip series not supported?

Should I add pullup resistors between pins 3 and/or 7 to Vcc? If so, any suggestion on what values?


Hi ManlyEchidna, I'm afraid I have not tested the JV series of flash memory with the library. I've just quickly glanced over the datasheet you've linked to and I don't see any reason why they shouldn't work. The Error message that you are getting is only meant for chips with HOLD or WP pins, so, if you don't have them, you can ignore it.

Could you please run the following steps and let me know what output you get?

  • Make sure #define RUNDIAGNOSTIC is uncommented in your SPIFlash.h file and save it.
  • Upload the Diagnostics.ino sketch to your Feather M0 after setting
SPIFlash flash(11);
  • Paste the serial output from the sketch in your reply.

Let's see if we can get the library working with your chips :)

Hey there! I'm having a hard time getting SPIFlash to work with a Spansion S25FL127S (MCU is an ATMega328p with Uno bootloader running at 16 MHz, 3.3v). I keep getting various errors, including 0x0B and 0x06; I suspect a wiring issue, however everything seems OK. Power and ground are OK, SPI lines are correct, CS is pulled high with a 10kohm resistor, and write protect and hold are both tied high. Any idea what's going wrong? Other devices on that same SPI bus work fine. (SPIFlash still errors out even with nothing else on the SPI bus.)

@compucat have you tried removing the pull up on the CS pin?

Yup, I've tried with CS pulled up, no pullup, write protect and hold floating, tied high, tied low. Nothing seems to work. Only change I've made to the FlashDiagnostics code is to set an alternative CS pin. Do you have a working schematic for an ATMega328p+Spansion setup?

EDIT: I've also tried wiring it to a stock Arduino Uno with resistors as level shifters, no dice. I might try again with a fresh chip just to rule out bad silicon.

EDIT 2: Tried a fresh chip, no dice.

Hi I am trying to use this library to access an LC W25Q80B memory modules with a Winbond 25Q80 from a BluePill STM32F103. http://www.chinalctech.com/index.php?_m=mod_product&_a=view&p_id=1066 It looks like a great library but I cant get anything from the FlashDiagnostics example. Reading the instructions I should remove the // from #define RUNDIAGNOSTIC in SPIFlash.cpp but I cant find it there but it is in the SPIFlash.h but it is already un-commented so I leave everything as is. The examples builds and runs on the STM but I only get the following output:

Initialising Flash memory..........
Chip Diagnostics initiated.

No Chip size defined by user

                                                                    SPIFlash Library version: 3.0.0
                                                                                Get ID

...JEDEC ID: ef4014h

If I connect using Arduino Pro Mini 3.3, I get:

Opening port
Port open
Initialising Flash memory..........
Chip Diagnostics initiated.

No Chip size defined by user

                                                                    SPIFlash Library version: 3.0.0
                                                                                Get ID

            JEDEC ID: ef4014h
            Manufacturer ID: efh
            Memory Type: 40h
            Capacity: 1048576 bytes
            Maximum pages: 4096
            Unique ID: 1153678118893824, 0x608414039E763900

            Erase Chip:         Data I/O test PASS          Time: 1.274 s
            Erase 64KB Block:   Data I/O test PASS          Time: 128.920 ms
            Erase 32KB Block:   Data I/O test PASS          Time: 109.400 ms
            Erase 4KB Sector:   Data I/O test PASS          Time: 42.328 ms

            Byte:           Data I/O test PASS          Write Time: 320 us, Read Time: 128 us
            Char:           Data I/O test PASS          Write Time: 328 us, Read Time: 128 us
            Word:           Data I/O test PASS          Write Time: 352 us, Read Time: 128 us
            Short:          Data I/O test PASS          Write Time: 360 us, Read Time: 128 us
            ULong:          Data I/O test PASS          Write Time: 384 us, Read Time: 136 us
            Long:           Data I/O test PASS          Write Time: 376 us, Read Time: 144 us
Error code: 0x0A
            Float:          Data I/O test FAIL          Write Time: 0 us,   Read Time: 160 us
            Struct:         Data I/O test PASS          Write Time: 160 us, Read Time: 160 us
            Byte Array:         Data I/O test PASS          Write Time: 5.288 ms,   Read Time: 888 us
            String:         Data I/O test PASS          Write Time: 424 us, Read Time: 152 us
            Power Down:         Data I/O test FAIL          Not all chips support power down. Please check your datasheet.
            Power Up:       Data I/O test PASS          Time: 176 us

Any suggestions please

Hi I am trying to use this library to access W25Q64JV with Arduino MEGA. But i coldn’t be successful.
W25Q64BV is obsolete and i used W25Q64JV.
Do you have any relevant ideas about this?


W25Q64BV is obsolete? Hmmm... why do you think so?

I have a funny problem with this kind of memory. Namely, I can't find any sketch which demonstrates the simpliest read/write operations with W25 chips. Can someone help with this?

@ Compucat : I’m afraid I can’t explain why that’s happening with you. The library appears to work fine with the S25FL127S I have. I’ll try out a few other chips this weekend and let you know if I face any issues.

@ TrekRider: I’m afraid the library does not officially support the BluePill. I have had a lot of trouble getting the USB bootloader working on my boards and gave up just before Christmas. However, I’m still keen on supporting the board, so, could you do me a favour and raise an issue on the Github page [here]? I’ll get going started again on getting the Blue pill supported. :smiley:

@ kucukkose: Thanks for raising an issue on Github about this. Could you please refer to my comments there and provide a little more information on what exactly the problem seems to be?

@ Gosh: What do you mean by simple sketch to demonstrate read/write operations? Are you looking for code that works with the SPIFlash library or SPI level code?

[u]Update: Library will be renamed in a couple of months.[/u]

The term 'SPI Flash' is a fairly common way to refer to Flash memory chips that communicate over the SPI protocol and there are a number of libraries that are named SPIFlash. When I first started work on this library in 2014, it was mostly as an exercise to improve my embedded systems programming skills. When I asked for it to be included in the list of Arduino libraries [in 2015], I did not really expect it to go very far or get very popular. But, before I knew it, I was releasing new versions every other month and I found the number of users got way bigger than I imagined it would. The amount of traffic the GitHub repository gets still surprises me.

A few months ago, Felix Rusu of LowPowerLab raised an issue [#83] about the problems the name of this library was causing the users of his library - also called SPIFlash. The fact that this library is in the Arduino Library manager meant that his users were being asked to upgrade their version of SPIFlash when the libraries were actually different. I can understand how much of an annoyance this can be for a user.

Felix's version of SPIFlash has been around for longer than this one and his library is a major part of his commercial line of development boards. Since I am a hobbyist developer (I'm a full-time geneticist & a part-time dabbler in ecology - if you're curious) and this library is not a commercial product with branding and trademarks to worry about, the least I can do is change the name of this library so it stops being an annoyance to Felix's customers.

On a side note, if you did not know already, Felix makes and sells a fantastic line of Arduino compatible boards - the Moteino series - and has developed a fantastic IoT protocol to use with them to add smarts to your home. In January this year, I finally got around to getting my hands on some of his boards and have been playing around with them. They are fantastic! I'd strongly recommend you check them out - if you haven't already done so.

I asked the Arduino developers if there was a way to migrate this library to a new name without breaking the upgrade path [Issue #6904] and was told that it was not possible. The only way is to pull my version of SPIFlash from the library manager and ask for a renamed version to be included in the library manager after.

So, this is what I have decided to do.:

  • The upcoming version - v3.1.0 - will be the last version to be released under the SPIFlash name.
  • Anyone downloading v3.1.0 of the library will be able to read this notice in the ReadMe file.
  • Anyone using v3.1.0 of the library will also see a notice in their Serial output directing them to the notice in the ReadMe file. (this can be removed by commenting out the "#define PRINTNAMECHANGEALERT" in "SPIFlash.h")
  • Version 3.2.0 will be released in a couple of months (in May most likely) under a new name. I'm currently thinking of calling it SPIMemory - suggestions are welcome.
  • SPIFlash will be removed from the library manager then and replaced with the new one

The only change will have to be made in end-user code will be to change the "#include SPIFlash.h" to "#include SPIMemory.h" (or whatever the new name will be). After the name change, rest assured that older versions will remain accessible and the development history of the library will be preserved.

I apologise for any trouble this might cause you - the end user - but, given the facts, it is the only thing I can do to be fair to Felix.

Thanks again for using SPIFlash and I hope you will continue to find it useful in whatever new name it will take on.