Cannot make a SD card reader working with Arduino Due
Show older comments
Hi, I'm triing to program a datalogger function into an S-function in Simulink R2017a for an Arduino Due but impossible to make it working.
My program is working good if I use it with ArduinoIDE, It was also working with simulink on an arduino UNO. I have the last simulink package
I have tried to use lot of differents library (No need to select some libraries in ArduinoIDE but it's needed in simulink and finaly I have taken the last Libraries I find on the computer (SD.h; SD.cpp; File.cpp; SPI.cpp;SPI.h). Before I had an error on SPIsetting when triing to compil with other library but know it's ok. My program run good but it never see the Sd card.
My code here:
Libraries:
#ifndef MATLAB_MEX_FILE
#include "SPI.cpp"
#include "SPI.h"
#include "SD.cpp"
#include "SD.h"
#include "file.cpp"
const int chipSelect = 10;
File logfile;
#endif
Discrete Update:
if (xD[0]!=1) {
# ifndef MATLAB_MEX_FILE
// initialize the SD card
if(!SD.begin(chipSelect)){
// fail if card is not present
return;
}
// create a new file
char filename[]="LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++)
{
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename))
{
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
logfile.println("Time,Sensor1");
# endif
xD[0]=1;
}
Outputs:
if (xD[0]==1){
#ifndef MATLAB_MEX_FILE
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
// log sensors
logfile.print(sensor1[0]);
logfile.println();
logfile.flush();
#endif
}
Before to have #include file.cpp the simulation was blocked at time 0 but know all the other function work fine. To see where the problem I had an output status and I see that the program was doing a loop at the begening:
// initialize the SD card
if(!SD.begin(chipSelect)){
// fail if card is not present
return;
}
I think it's a bug on the arduino library on simulink but I will be really happy if you have a solution. I was searching for 7days and today I think I had test all I can.
Thank you all
Regards
Answers (0)
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!