0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MaixCubeでSdFatを使う

Posted at

はじめに

MaixシリーズのArduino開発環境MaixduinoにもSDカードドライバーは含まれていますが、ロングファイルネームに対応していないようです。SdFatライブラリーを使ってみましょう。

SdFat

オリジナルはArduino SdFat Libaryです。USE_STANDARD_SPI_LIBRARYの指定で動作しました。

USE_STANDARD_SPI_LIBRARY 1

サンプル

# include <Arduino.h>
# include <SPI.h>
# include <SdFat.h>  // https://github.com/greiman/SdFat

SPIClass SPI_0(SPI0);
SdFat sd;

const uint8_t SD_CS = SS;   // chip select for sd

//------------------------------------------------------------------------------
// print error msg, any SD error codes, and halt.
// store messages in flash
# define errorExit(msg) errorHalt(F(msg))
# define initError(msg) initErrorHalt(F(msg))
//------------------------------------------------------------------------------

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println("SdFat_ListDir");

  if (!sd.begin(SS, SPISettings(20000000U, MSBFIRST, SPI_MODE0))) {
    sd.initError("sd:");
  }

  sd.ls(LS_DATE | LS_SIZE | LS_R);

  //File read
  Serial.println("");
  Serial.println("SdFat_Reading...maixpy.bin");

  int size = 0;
  uint8_t buff[1024];
  File f = sd.open("maixpy.bin", O_READ);
  while (f.available() > 0) {
    int bytes = f.readBytes(buff, 1024);
    size += bytes;
  }
  f.close();
  Serial.printf("total = %d\n", size);
}

void loop() {
  sleep(1);
}

ロングファイルネームが使えました

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?