Transfering data from SPIflash to SD on Adalogger M0

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mkschneider
 
Posts: 5
Joined: Mon Feb 12, 2018 4:50 pm

Transfering data from SPIflash to SD on Adalogger M0

Post by mkschneider »

I am fairly new to C++, so apologies for a stupid question. I have an Adalogger M0 connected to a GPS feather. I can parse the GPS data and store it to either the SD card or Flash memory. However, I fail to use both at the same time. My intention is to store GPS data to Flash every minute and transfer this data to the SD card every hour. I am stuck with the file class which can either be used for SPIFlash or SD. The IDE tells me "class File : public Stream"
Many thanks for any helpful advice.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by adafruit_support_mike »

We prefer to avoid 'stupid'.. it's a very beginner-unfriendly word. Some questions involve basic information, but we all have to learn that information somewhere. This is a friendly place to do that.

Post the code you're using now (between CODE tags please) and we'll use that as a starting point to where you want to go.

User avatar
mkschneider
 
Posts: 5
Joined: Mon Feb 12, 2018 4:50 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by mkschneider »

Sorry for my late reply. I have worked further, trying the simple examples of the Adafruit SPIFlash Library. Even if just verifying these sketches (for example fatfs_datalogging.ino) I am getting
Arduino: 1.8.5 (Windows 10), Board: "Adafruit Feather M0"
fatfs_datalogging:30: error: 'SS1' was not declared in this scope
#define FLASH_SS SS1 // Flash chip SS pin.
E:\Arduino\libraries\Adafruit_SPIFlash\examples\fatfs_datalogging\fatfs_datalogging.ino:33:25: note: in expansion of macro 'FLASH_SS'
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI
fatfs_datalogging:31: error: 'SPI1' was not declared in this scope
#define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?
E:\Arduino\libraries\Adafruit_SPIFlash\examples\fatfs_datalogging\fatfs_datalogging.ino:33:36: note: in expansion of macro 'FLASH_SPI_PORT'
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI
exit status 1
'SS1' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Many thanks for any ideas what's wrong with my setup.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by adafruit_support_mike »

Those errors say the code is trying to use values that aren't defined anywhere.

To know what's going wrong we need to see the code itself please.

User avatar
mkschneider
 
Posts: 5
Joined: Mon Feb 12, 2018 4:50 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by mkschneider »

I forgot to say that I disconnected the GPS feather. So I am executing the following code on an Adalogger M0.

Code: Select all

// Adafruit SPI Flash FatFs Simple Datalogging Example
// Author: Tony DiCola
//
// This is a simple dataloging example using the SPI Flash
// FatFs library.  The example will open a file on the SPI
// flash and append new lines of data every minute. Note that
// you MUST have a flash chip that's formatted with a flash
// filesystem before running.  See the fatfs_format example
// to perform this formatting.
//
// Usage:
// - Modify the pins and type of fatfs object in the config
//   section below if necessary (usually not necessary).
// - Upload this sketch to your M0 express board.
// - Open the serial monitor at 115200 baud.  You should see the
//   example print a message every minute when it writes a new
//   value to the data logging file.
#include <SPI.h>
#include <Adafruit_SPIFlash.h>
#include <Adafruit_SPIFlash_FatFs.h>

// Configuration of the flash chip pins and flash fatfs object.
// You don't normally need to change these if using a Feather/Metro
// M0 express board.
#define FLASH_TYPE     SPIFLASHTYPE_W25Q16BV  // Flash chip type.
                                              // If you change this be
                                              // sure to change the fatfs
                                              // object type below to match.

#define FLASH_SS       SS1                    // Flash chip SS pin.
#define FLASH_SPI_PORT SPI1                   // What SPI port is Flash on?

Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT);     // Use hardware SPI

// Alternatively you can define and use non-SPI pins!
// Adafruit_SPIFlash flash(FLASH_SCK, FLASH_MISO, FLASH_MOSI, FLASH_SS);

Adafruit_W25Q16BV_FatFs fatfs(flash);

// Configuration for the datalogging file:
#define FILE_NAME      "data.csv"


void setup() {
  // Initialize serial port and wait for it to open before continuing.
  Serial.begin(115200);
  Serial.println("Adafruit SPI Flash FatFs Simple Datalogging Example");

  // Initialize flash library and check its chip ID.
  if (!flash.begin(FLASH_TYPE)) {
    Serial.println("Error, failed to initialize flash chip!");
    while(1);
  }
  Serial.print("Flash chip JEDEC ID: 0x"); Serial.println(flash.GetJEDECID(), HEX);

  // First call begin to mount the filesystem.  Check that it returns true
  // to make sure the filesystem was mounted.
  if (!fatfs.begin()) {
    Serial.println("Error, failed to mount newly formatted filesystem!");
    Serial.println("Was the flash chip formatted with the fatfs_format example?");
    while(1);
  }
  Serial.println("Mounted filesystem!");

  Serial.println("Logging data every 60 seconds...");
}

void loop() {
  // Open the datalogging file for writing.  The FILE_WRITE mode will open
  // the file for appending, i.e. it will add new data to the end of the file.
  File dataFile = fatfs.open(FILE_NAME, FILE_WRITE);
  // Check that the file opened successfully and write a line to it.
  if (dataFile) {
    // Take a new data reading from a sensor, etc.  For this example just
    // make up a random number.
    int reading = random(0,100);
    // Write a line to the file.  You can use all the same print functions
    // as if you're writing to the serial monitor.  For example to write
    // two CSV (commas separated) values:
    dataFile.print("Sensor #1");
    dataFile.print(",");
    dataFile.print(reading, DEC);
    dataFile.println();
    // Finally close the file when done writing.  This is smart to do to make
    // sure all the data is written to the file.
    dataFile.close();
    Serial.println("Wrote new measurement to data file!");
  }
  else {
    Serial.println("Failed to open data file for writing!");
  }

  Serial.println("Trying again in 60 seconds...");

  // Wait 60 seconds.
  delay(60000L);
}
Thanks for your answer.

User avatar
mkschneider
 
Posts: 5
Joined: Mon Feb 12, 2018 4:50 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by mkschneider »

And I get the same behaviour with any other sketch of the Adafruit SPIFlash library, also with fatfs_format.ino.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by adafruit_support_mike »

Ah, I see what's happening.

That sketch was written for the Feather M0 Express, which has a 2MB Flash chip on the PCB, but external to the microcontroller. The Adalogger M0 doesn't have that chip, so you'll need different code to read the microcontroller's internal 256K Flash array.

This library talks to the internal Flash:

https://github.com/cmaglie/FlashStorage

User avatar
mkschneider
 
Posts: 5
Joined: Mon Feb 12, 2018 4:50 pm

Re: Transfering data from SPIflash to SD on Adalogger M0

Post by mkschneider »

Thanks a lot for your help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”