Arduino からSPI経由SDcard を使ってloggerを作りたい

조회 수: 9 (최근 30일)
裕利 中尾
裕利 中尾 2023년 1월 17일
댓글: 裕利 中尾 2023년 2월 15일
SDmodule を使いたいです。
SPI WritRead block の help にSDcardへの store の記載がありますが、data form が分かりません。
Arduino IDE の #include <SC.h> のライブラリを使えればいいのだと思いますが、
Simulink のモデル中にどのように取り込めばいいのか教えていただけるとありがたいです。

답변 (1개)

Toshinobu Shintai
Toshinobu Shintai 2023년 1월 31일
편집: Toshinobu Shintai 2023년 1월 31일
一般的には、以下で説明されている MATLAB System ブロックを使ったワークフローを推奨しています。
  댓글 수: 4
裕利 中尾
裕利 中尾 2023년 2월 10일
ありがとうございます。
エラーマークが消えました。
続けてみます。
裕利 中尾
裕利 中尾 2023년 2월 15일
根本的に skill 不足で解決できないエラーだらけです。
***
Recommended Skills
To develop a device driver block for Arduino hardware boards, familiarity with the following skills is recommended:
***
↑他に s-function を使う方法が公開されていて試していますが、
ビルド時、以下のログが出ました。
・・・正常に作成されたが結局 failed の原因がわかりません。
Arduino IDE のサンプルスケッチ(.ino)をそのまま書き込む方法があると助かるのですが・・・
### 'SD_logger.c' は正常に作成されました
### 'SD_logger_wrapper.c' は正常に作成されました
### 'SD_logger.tlc' は正常に作成されました
Compile of 'SD_logger.c' failed.
<SD_logger_wrapper.c>
/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
#include <SPI.h>
#include <SD.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
const int chipSelect =53;
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Start function
*
*/
void SD_logger_Start_wrapper(real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */
/*
* カスタム開始コードをここに配置します。
// void setup(){
// Open serial communications and wait for port to open:
Serial.begin(31250);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
//see if the dcard is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed,or not present");
//don't do anythingmore:
while(1);
}
Serial.println("card initialized.");
*/
/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Output function
*
*/
void SD_logger_Outputs_wrapper(const uint16_T *Time,
const real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* このサンプルは、出力を入力と等しく設定します
//make a stringf for assembling the data to log:
String dataString = "";
// read inputs:
for (uint16 Time){
}
// open the file. note that only one file can be open at a time,
// lso you have to vlose this one file can be opening another.
File dataFile = SD.open("datalog.txt,FILE_WRITE);
// if the file is available, wtrite to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file is'nt open, pop up an error;
else{
Serial.println("error opening datalog.txt")
}
*/
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
void SD_logger_Update_wrapper(const uint16_T *Time,
real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Device Driver Blocks에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!