STM32F3 Modul CAN.. #include <SD.h> can't write to SDCard

Started by mgolbs, February 08, 2024, 09:58:22 AM

Previous topic - Next topic

mgolbs

Hello,

we bay a lot of OLIMEXINO-STM32F3 modules. CAN works, LCD works, SDCard are can read, but not write. This is my problem. Here a part of Code:

// include the SD library:
#include <SPI.h>
#include <SD.h>
File Datendatei_Zeiger;
//const char dateiname[] = "240207.txt";
const char dateiname[] = "test.txt";
const int chipSelect = 25;

Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  Filesystem_Zeiger.openRoot(volume);

  Filesystem_Zeiger.ls(LS_R | LS_DATE | LS_SIZE);

  SD.begin();
  Datendatei_Zeiger = SD.open(dateiname, FILE_WRITE);
  if (!Datendatei_Zeiger) {
    Serial.print("error opening ");
    Serial.println(dateiname);
    while (true);
  }

  Datendatei_Zeiger.println("einige Zahlen schreiben 1, 2, 3.");
  Datendatei_Zeiger.flush();
    // close the file:
  Datendatei_Zeiger.close();

//  MOD_LCD3310_2 ();

The serial output with card one:
QuoteInitializing SD card...Wiring is correct and a card is present.

Card type:         SDHC
Clusters:          122846
Blocks x Cluster:  64
Total Blocks:      7862144

Volume type is:    FAT32
Volume size (Kb):  3931072
Volume size (Mb):  3838
Volume size (Gb):  3.75
20:29:13
24-02-07

Files found on the card (name, date and size in bytes):
error opening test.txt

The serial output with card two:

QuoteInitializing SD card...Wiring is correct and a card is present.

Card type:         SDHC
Clusters:          242944
Blocks x Cluster:  64
Total Blocks:      15548416

Volume type is:    FAT32
Volume size (Kb):  7774208
Volume size (Mb):  7592
Volume size (Gb):  7.41
08:26:51
24-02-08

Files found on the card (name, date and size in bytes):
2019-0~1.TXT  2019-06-30 19:12:10 1189
2019-0~1.PNG  2019-01-25 11:30:48 67806
2019-0~1.PY   2019-01-14 12:55:50 43087
2019-0~2.PY   2019-01-23 13:09:42 47226
2019-0~3.PY   2019-01-25 10:21:30 49093
2019-0~4.PY   2019-01-30 09:16:32 48489
2019-0~5.PY   2019-01-25 08:38:58 48285
2019-0~6.PY   2019-01-25 12:45:22 49251
2019-0~7.PY   2019-01-25 11:52:02 48024
2019-0~8.PY   2019-01-30 09:21:24 48489
2019-0~9.PY   2019-02-07 10:55:48 2671
ELASTO~1.PY   2019-01-07 11:22:44 15274
ELASTO~2.PY   2019-01-14 12:39:54 42644
2019-0~5.PY   2019-01-25 08:38:58 48285
2019-0~6.PY   2019-01-25 12:45:22 49251
2019-0~7.PY   2019-01-25 11:52:02 48024
2019-0~8.PY   2019-01-30 09:21:24 48489
2019-0~9.PY   2019-02-07 10:55:48 2671
ELASTO~1.PY   2019-01-07 11:22:44 15274
ELASTO~2.PY   2019-01-14 12:39:54 42644
2019-0~1      2019-07-01 07:53:00 3410006
2019-0~2      2019-07-01 07:56:22 3410347
2019-0~3      2019-07-01 07:56:42 3410347
2019-0~4      2019-07-01 07:57:04 3410347
MINIFFT/      2019-07-01 10:29:40
  2019-0~1.PY   2019-07-01 09:18:24 41451
  2019-0~1.LOG  2019-07-01 09:25:44 0
  2019-0~2.PY   2019-07-01 10:28:48 4135
  2019-0~1.PDF  2019-07-01 08:13:50 21708
  2019-0~1      2019-07-01 08:43:30 3410006
  2019-0~2.PDF  2019-07-01 08:15:32 13070
AK_SIM~1/     2019-07-01 09:46:34
  2019-A~1.PPT  2019-07-01 06:47:58 480240723
  2019-0~1/     2019-07-01 09:46:30
    00001.MTS     2019-05-10 06:37:22 39186432
    00005.MTS     2019-05-10 06:39:40 38092800
    2018-0~1.PDF  2019-06-27 12:13:12 1298312
    2018-0~2.PDF  2018-09-20 11:14:02 732850
    2019-0~1.PDF  2019-06-27 13:20:04 1346006
    2019-A~1.PPT  2019-07-01 05:15:14 2163435
    THUMBS.DB     2019-07-01 06:56:02 39424
  2019-0~1.PPT  2019-06-26 14:22:52 19206147
  2019-0~2.PPT  2019-06-28 09:56:10 5037962
  2019-A~2.PPT  2019-07-01 07:11:54 38896971
2017-0lp.csv  1980-00-00 00:00:00 28215
error opening test.txt

I test a lot, how shore file name, "8.3", different SDCards, spezial SDCard format program, //#include <STM32SD.h>, const int chipSelect = 25;... I work with Arduino 2.3.0 under Debian 11, but not clean my problems. What is my mistake? About informations I'm very happy.

Greeting Markus


http://up-and-down.org/Olimex/2024-02-10-Olimex-SDCard-Problem.png
,,Wichtig ist nicht die Menge des Wissens, sondern die Güte. Man kann sehr viel wissen, dabei aber nicht einmal das Nötigste."
Leo Tolstoi

LubOlimex

Do you have anything connected to GPIO1 connector?

Did you try with another SD card library? Maybe try SDFat. A lot of people have complained about the built in SD library in the past. Try with another external library.
Technical support and documentation manager at Olimex

mgolbs

Hello,

many thanks!

Here my build:

http://up-and-down.org/Olimex/2024-02-08-STM32_build.JPG[

I use RTC, the Olimex LCD3310 modul and in future also the 4 AD ports, optional equipment CAN. In this code CAN not activ, not implement yet.

I will try "try SDFat or external library".

Greeting Markus

,,Wichtig ist nicht die Menge des Wissens, sondern die Güte. Man kann sehr viel wissen, dabei aber nicht einmal das Nötigste."
Leo Tolstoi

LubOlimex

The hardware setup looks fine. It is probably related to the software, so indeed give some other SD library a try.
Technical support and documentation manager at Olimex

mgolbs

Hello,

I looked to "#include "SdFat.h"" but is a big mix from all. :-) The tests I tray, so I can't compile without many adaptation, but I'm a mechanic not a software specialist, too complex for me... Many year I use AVR's...

Now it works with original lib "#include <SD.h>"

With a debian 10 gparted I format sd to fat16, but also not works.

So I expand the code:
    SD.begin(chipSelect);
//  SD.begin();
   Datendatei_Zeiger = SD.open(dateiname, FILE_WRITE);
//    Datendatei_Zeiger = SD.open("test.txt", FILE_WRITE);
  if (!Datendatei_Zeiger) {
    Serial.print("error opening ");
    Serial.println(dateiname);
    while (true);
  }

View on serial:
QuoteInitializing SD card...Wiring is correct and a card is present.

Card type:         SDHC
Clusters:          61562
Blocks x Cluster:  128
Total Blocks:      7879936

Volume type is:    FAT16
Volume size (Kb):  3939968
Volume size (Mb):  3847
Volume size (Gb):  3.76
13:42:44
24-02-08

Files found on the card (name, date and size in bytes):
TEST.TXT      2000-01-01 01:00:00 170
240207.TXT    2000-01-01 01:00:00 34

Thanks and greeting Markus
,,Wichtig ist nicht die Menge des Wissens, sondern die Güte. Man kann sehr viel wissen, dabei aber nicht einmal das Nötigste."
Leo Tolstoi