chipKIT® Development Platform

Inspired by Arduino™

File date on SD card

Created Wed, 24 Sep 2014 08:24:10 +0000 by tcsaba101


tcsaba101

Wed, 24 Sep 2014 08:24:10 +0000

Please tell me how can I write the date of file creation on the SD card on chipkit Fubarino SD, using Uecide 0.8.7j built in SD library.

Thanks.


majenko

Wed, 24 Sep 2014 08:51:53 +0000

This is the source code to the library's "ls" function:

void SdFile::ls(uint8_t flags, uint8_t indent) {
  dir_t* p;

  rewind();
  while ((p = readDirCache())) {
    // done if past last used entry
    if (p->name[0] == DIR_NAME_FREE) break;

    // skip deleted entry and entries for . and  ..
    if (p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') continue;

    // only list subdirectories and files
    if (!DIR_IS_FILE_OR_SUBDIR(p)) continue;

    // print any indent spaces
    for (int8_t i = 0; i < indent; i++) Serial.print(' ');

    // print file name with possible blank fill
    printDirName(*p, flags & (LS_DATE | LS_SIZE) ? 14 : 0);

    // print modify date/time if requested
    if (flags & LS_DATE) {
       printFatDate(p->lastWriteDate);
       Serial.print(' ');
       printFatTime(p->lastWriteTime);
    }
    // print size if requested
    if (!DIR_IS_SUBDIR(p) && (flags & LS_SIZE)) {
      Serial.print(' ');
      Serial.print(p->fileSize);
    }
    Serial.println();

    // list subdirectory content if requested
    if ((flags & LS_R) && DIR_IS_SUBDIR(p)) {
      uint16_t index = curPosition()/32 - 1;
      SdFile s;
      if (s.open(this, index, O_READ)) s.ls(flags, indent + 2);
      seekSet(32 * (index + 1));
    }
  }
}

It uses readDirCache() to get each entry in the current directory which can then be examined for dates, times, name, attributes, etc.


tcsaba101

Wed, 24 Sep 2014 20:44:45 +0000

I don't have any idea what to do.

I suppose this is the code part what belongs to:

// print modify date/time if requested
if (flags & LS_DATE) {
   printFatDate(p->lastWriteDate);
   Serial.print(' ');
   printFatTime(p->lastWriteTime);
}

But frankly, this is far beyond my understandig.

Where should I start to understand it?


majenko

Wed, 24 Sep 2014 21:41:09 +0000

dir_t* p;

That is a pointer to a directory entry.

rewind();

That starts the directory listing at the beginning.

while ((p = readDirCache())) {

That gets each directory entry in order and points "p" to it. You can now examine what is in p.

p->name is the file name. The first character can be a special character representing a non-allocated file, or a file that has been deleted.

p->lastWriteDate
and 
p->lastWriteTime

are what they say they are.

I'll leave the rest to your imagination ;)


tcsaba101

Thu, 25 Sep 2014 04:42:21 +0000

Thanks for the explanation. Now I have a foggy idea what to do. I have big gaps in my knowledge of C programming.

Have found this topic: http://forum.arduino.cc/index.php?topic=115754.0

Where can I found the declaration of "dir_t"? I couldn't find what is the exact meaning of the "->" operator? (struct member referencing?)


tcsaba101

Thu, 25 Sep 2014 06:22:21 +0000

I have found the detailed solution:

https://github.com/greiman/SdFat-beta Timestamp example.

Will it work in the chipkit + uecide environment?


randomrichard

Tue, 18 Nov 2014 16:12:36 +0000

I am trying to access data on the SD card on my Fubarino SD using the SD examples provided in MPIDE (using them in UECIDE for convenience). I assumed that the "chipSelect_SD" pin is 27 on the Fubarino SD but the UECIDE's serial terminal states that "initialization failed" in all cases, whether using 27, or 4, 10, 53 or whatever else has been suggested in examples. Can anyone show me some example code that actually works, please?

By the way, I am assuming the following are synonyms:

chipSelect_SD = CS = SS pin


majenko

Tue, 18 Nov 2014 17:04:46 +0000

The SD libraries in MPIDE and UECIDE are quite different beasts. I have made numerous improvements to UECIDE's SD library to massively increase the speed.

Last time I tried it I had no problems using it,

Just to test, I just grabbed a Fubarino SD and installed the CardInfo example - changed the chip select to:

const int chipSelect_SD_default = 27; // Change 10 to 53 for a Mega

The only caveat with working with the SD of course though is the serial doesn't wait for you to open the port, so I add this straight after the Serial.begin:

while (!Serial);
  delay(1000);

That way you get to see the first bit in setup() as you open the serial port.

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

Card type: SDHC

Volume type is FAT16

Volume size (bytes): 58662912
Volume size (Kbytes): 57288
Volume size (Mbytes): 55

Files found on the card (name, date and size in bytes):
LICENS~1.ORA  2013-09-25 21:57:48 18974
BOOTCODE.BIN  2014-10-29 11:28:56 17840
CMDLINE.TXT   2014-10-29 11:28:56 146
CONFIG.TXT    2014-10-29 11:28:58 259
FIXUP.DAT     2014-10-29 11:28:56 6115
FIXUP_CD.DAT  2014-10-29 11:28:56 2324
FIXUP_X.DAT   2014-10-29 11:28:56 9166
ISSUE.TXT     2014-10-29 11:28:56 137
KERNEL.IMG    2014-10-29 11:28:56 3265968
START.ELF     2014-10-14 10:18:26 3852604
START_CD.ELF  2014-10-29 11:28:56 533080
START_X.ELF   2014-10-29 11:28:56 3572200
4DSPLASH.RAW  2014-10-19 20:51:34 262144
BOOT.SCR      2014-10-12 18:59:48 85
KERNEL~1.IMG  2014-10-29 11:28:56 3200400
U-BOOT.BIN    2014-10-12 18:59:54 255244
UENV.TXT      2014-11-04 16:47:40 640
CONFIG~1.TXT  2014-10-14 10:18:38 259
KERNEL4D.IMG  2014-10-19 20:51:28 3203528

randomrichard

Tue, 18 Nov 2014 18:21:55 +0000

Thanks Majenko, that works. And the UECIDE environment is indeed massively better than previous sketch IDE's. R


majenko

Tue, 18 Nov 2014 18:26:39 +0000

It's all to do with the lack of an FT232 or similar chip as a USB interface. You get a direct connection to the USB interface in the chip, like the Arduino Leonardo, Yùn, and the second USB port on the Due. When you press the reset button the chip resets, and the USB connection disappears.

It's not a good system if you're going to be resetting all the time - some operating systems don't like it much, but you can get around it by connecting a real USB UART adapter to the TX/RX pins and using Serial0 instead of Serial.


randomrichard

Tue, 18 Nov 2014 18:31:09 +0000

Thanks for the advice. I quickly edited my comment about resets because I found that the resetting does work with the Fubarino with the delay (I use 5 sec) if the reset operation precedes opening the terminal. It's obviously (another) Windows issue.


randomrichard

Tue, 18 Nov 2014 21:27:58 +0000

This may be helpful to others using software built around the UECIDE DumpFile SD example sketch to send data to a VB.NET terminal. The PC will only, in my experience, accept a file of numerical data if it is in lines of integers saved in a text file (*.txt) that is in UTF-8 format. I have found that the surest way of achieving this format is to take, say, the EXCEL *.txt file, open it in Textpad and then save it in UTF-8, not ANSI, format. Long-winded but it works. I used a column of integers thus 1, 2, 3, ..., 1024 to confirm this. Now I can check my FFT correlation program with model signals in real time. At last! If anyone knows how to get EXCEL to output UTF-8 please let me know too.