Jump to content
43oh

[Energia Library] Petit FatFS SD Card Library


Recommended Posts

  • Replies 148
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hello,   This is a port of ChaN Petit FatFS SD library targeted to low RAM microcontrollers and offers a minimal FAT implementation, with limited write support. For more details see http://elm-chan.

A small update: - all config settings in one file - pffconf.h - a soft SPI driver ( shuftIn/shiftOut ) that can be enabled in pffconf.h. It defaults on HW SPI pins, but these can be changed using Fa

Hi, i just wanted to report that the library won't compile with Energia release 0101E0011 and the F5529 Launchpad because "DIR" is already defined in \energia-0101E0011\hardware\tools\msp430\msp430\in

Posted Images

Sorry, I still don't get it. Is it possible to write anything on SD card with msp430g2553? In this case I will store every log string in a separate file. Or maybe I need to find SD card with <512 bytes sectors? I'm currently using very old 16mb Toshiba card. Mb it is the right one...

Link to post
Share on other sites

Sorry, I still don't get it. Is it possible to write anything on SD card with msp430g2553? In this case I will store every log string in a separate file. Or maybe I need to find SD card with <512 bytes sectors? I'm currently using very old 16mb Toshiba card. Mb it is the right one...

SD cards with sectors under 512 bytes do not exist, some with 1024 bytes or 2048 bytes sectors exist, albeit somewhat out of spec (for the 2048 bytes version).

The only real way to write data to the SD card is to prepare the card in a PC to have a hard sequential order of sectors within one file. Then write to that sector in a sequential way. You will keep the writing cycle open this way so you can push more data to it before finishing the write cycle.

This is quite a crude and inelegant way, but it may very well work.

Link to post
Share on other sites

roadrunner84, thank you! Now the idea is clear. Could you please give me an idea how to implement write to sd card in this way? Is it possible to do it in Energia or something more sophisticated is required?

Everything is possible in Energia, it's just C++ with some framework.

I cannot help you to fix your issue, you'll have to rewrite large portions of the SD library to get thing working this way.

Link to post
Share on other sites

Everything is possible in Energia, it's just C++ with some framework.

I cannot help you to fix your issue, you'll have to rewrite large portions of the SD library to get thing working this way.

 

 

Thank you for your help.

 

Considering the fact that I'm just a newbie, it's impossible for me to rewrite large portions of the SD library. So it looks more reasonable to use a bluetooth module instead of SD card and just send temp. sensor data right to the server.

Link to post
Share on other sites

The only file on sdcard is "SD card test.txt",

PFatFS uses the 8.3 naming convention.That means, a longer name will be "truncated" to 8 characters. In the case of a file with a name as you used ("SD card test.txt"), PFatFS shows me it as "SDCARD~1.TXT".

Maybe an ideea will be to start keeping just the directory listing part from the test sketch, to see if you have communication and just the name is wrong, or you don't have communication at all.

/*-----------------------------------------------------------------------*/
/* Program Main                                                          */
/*-----------------------------------------------------------------------*/

void loop()
{
    Serial.println();
    Serial.println("Open root directory.");
    delay(100);
        rc = FatFs.opendir(&dir, "");
    if (rc) die(rc);

    Serial.println();
        Serial.println("Directory listing...");
        delay(100);
    for (; {
        rc = FatFs.readdir(&dir, &fno);    /* Read a directory item */
        if (rc || !fno.fname[0]) break;    /* Error or end of dir */
        if (fno.fattrib & AM_DIR) {Serial.print("<dir>\t"); Serial.println(fno.fname);delay(100);}
        else {Serial.print(fno.fsize);Serial.print("\t"); Serial.println(fno.fname);delay(100);}
    }
    if (rc) die(rc);

        Serial.println();
    Serial.print("Test completed.");
    //for (; ;
}

PS I'm using a tivac board.

Link to post
Share on other sites

PFatFS uses the 8.3 naming convention.That means, a longer name will be "truncated" to 8 characters. In the case of a file with a name as you used ("SD card test.txt"), PFatFS shows me it as "SDCARD~1.TXT".

Maybe an ideea will be to start keeping just the directory listing part from the test sketch, to see if you have communication and just the name is wrong, or you don't have communication at all.

/*-----------------------------------------------------------------------*/
/* Program Main                                                          */
/*-----------------------------------------------------------------------*/

void loop()
{
    Serial.println();
    Serial.println("Open root directory.");
    delay(100);
        rc = FatFs.opendir(&dir, "");
    if (rc) die(rc);

    Serial.println();
        Serial.println("Directory listing...");
        delay(100);
    for (; {
        rc = FatFs.readdir(&dir, &fno);    /* Read a directory item */
        if (rc || !fno.fname[0]) break;    /* Error or end of dir */
        if (fno.fattrib & AM_DIR) {Serial.print("<dir>\t"); Serial.println(fno.fname);delay(100);}
        else {Serial.print(fno.fsize);Serial.print("\t"); Serial.println(fno.fname);delay(100);}
    }
    if (rc) die(rc);

        Serial.println();
    Serial.print("Test completed.");
    //for (; ;
}

PS I'm using a tivac board.

 

omg! Thank you so much!

Your code really works :)

 

 

Open root directory.

 
Directory listing...
4096 ~1.TRA
<dir> TRASHE~1
<dir> FSEVEN~1
37 SDCARD~1.TXT
4096 _SDCAR~1.TXT
 
Test completed.

 

 

Now I'm gonna try to write on SD card :)

Link to post
Share on other sites

There are some limitation in using the write function. Calin has listed them in the post 4.

Impossibility to change the size of the file is one of them.

 

Hopefully, it is possible to live with. Could you evaluate my plan?

1) Create two 2mb "empty" files on SD card (fileA and fileB).

2) Write log data to fileA and remember how much space already have taken.

3) When fileA is almost full with log data, start writing to fileB

4) When fileB is almost full with log data, start writing to fileA and so on.

 

Considering the fact that 1 line of log less then 32 bytes (YYYY.MM.DD HH.MM Temp) and mcu check temperature once in a minute, 2mb file can store data for one month and a half. File size could be increased, 2mb files are just for test purposes.

Link to post
Share on other sites
  • 1 month later...

To select another SPI port on the LM4F120 or TM4C123, have a look at the Sd2Card::init function.

 

uint8_t Sd2Card::init(uint8_t chipSelectPin, uint8_t sckRateID, int8_t SPI_Port, int8_t cardDetectionPin, int8_t level)

 
#if defined(__LM4F120H5QR__) || defined(__TM4C1230C3PM__) || defined(__TM4C123GH6PM__) || defined(__TM4C129XNCZAD__) || defined(__TM4C1294NCPDT__)
    // LM4F and TM4C specific
    if (SPI_Port >= 0) {
        SPI_for_SD.setModule(SPI_Port);
    }
#endif
 
Link to post
Share on other sites
  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...