Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w25q128_test #28

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions test/w25q128_test/w25q128_test.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <SPI.h>
#include <SdFat.h>
#include <Adafruit_SPIFlash.h>

#ifndef FLASH_CONFIG_H_
#define FLASH_CONFIG_H_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FLASH_CONFIG_H_はインクルードガードってやつなのでこれ関連の行は消してOK
https://www.jpcert.or.jp/sc-rules/c-pre06-c.html


#define EXTERNAL_FLASH_USE_CS 22
#define EXTERNAL_FLASH_USE_SPI SPI

Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);

#endif

Adafruit_SPIFlash flash(&flashTransport);

FatVolume fatfs; // file system object from SdFat

#define FILE_NAME "data.csv" //ファイル名を指定

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

// Initialize flash library and check its chip ID.
if (!flash.begin()) {
Serial.println("Error, failed to initialize flash chip!");
while (1) {
delay(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(&flash)) {
Serial.println("Error, failed to mount newly formatted filesystem!");
Serial.println(
"Was the flash chip formatted with the fatfs_format example?");
while (1) {
delay(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.
File32 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
// 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();
dataFile.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open,print,closeにかかる時間をそれぞれmicros()使ってマイクロ秒単位で測って欲しい

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); //時間を適切な時間に修正
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]

Loading