Using a QSPI DIP breakout board with Arduino involves wiring up the QSPI chip to your Arduino-compatible microcontroller, installing the Adafruit_SPIFlash library and running the provided example code.

Wiring

Wire as shown for a 3.3V board like a Feather. These breakouts are only good for 3.3V logic and power! Do not use them with a 5V board, like an Arduino Uno!

Here is an Adafruit Feather M4 wired up to the QSPI DIP breakout board on a solderless breadboard:

  • Board 3.3V to breakout 3V (red wire)
  • Board GND to breakout G (black wire)
  • Board pin 11 to breakout IO0 (blue wire)
  • Board pin 12 to breakout IO1 (green wire)
  • Board pin 13 to breakout CLK (yellow wire)
Only use these breakouts with 3.3V logic and power!

Library Installation

You can install the Adafruit SPIFlash library for Arduino using the Library Manager in the Arduino IDE.

Click the Manage Libraries ... menu item, search for Adafruit SPIFlash, and select the Adafruit SPIFlash library:

If asked about dependencies, click "Install all".

If the "Dependencies" window does not come up, then you already have the dependencies installed. 

If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!

Example Code

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>

#include "SdFat.h"

#include "Adafruit_SPIFlash.h"

// for flashTransport definition
#include "flash_config.h"

Adafruit_SPIFlash flash(&flashTransport);

// file system object from SdFat
FatVolume fatfs;
File32 myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    delay(
        10); // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Initializing Filesystem on external flash...");

  // Init external flash
  flash.begin();

  // Open file system on the flash
  if (!fatfs.begin(&flash)) {
    Serial.println("Error: filesystem is not existed. Please try SdFat_format "
                   "example to make one.");
    while (1) {
      yield();
      delay(1);
    }
  }

  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = fatfs.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = fatfs.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

Upload the read/write sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the initialization of the QSPI flash module over SPI. Then, a text.txt file is written to the flash chip. Finally, the contents of the text.txt file are read back and printed to the Serial Monitor.

This guide was first published on Nov 16, 2022. It was last updated on May 16, 2024.

This page (Arduino) was last updated on May 16, 2024.

Text editor powered by tinymce.