-
Notifications
You must be signed in to change notification settings - Fork 0
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
w25q128_test #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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_ | ||
|
||
#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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. open,print,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); //時間を適切な時間に修正 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FLASH_CONFIG_H_
はインクルードガードってやつなのでこれ関連の行は消してOKhttps://www.jpcert.or.jp/sc-rules/c-pre06-c.html