43oh

[Energia Library] Petit FatFS SD Card Library

Recommended Posts

You can use SD cards, but you must write on-the-fly. Since (as stated) you cannot cache a sector (which are 512 bytes for almost all cards), since the msp430g2553 has only 256 bytes of RAM.

• Replies 148
• Created

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...

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.

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?

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.

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.

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.

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 (; {
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.

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 (; {
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!

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

Share on other sites

It is possible to write into my file ("SDCARD~1.TXT"), but by some reason I can't exceed initial size (37 bytes). Could someone please explain me the reason why? Is it related with msp430g2553 ram size?

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.

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.

Share on other sites

Hello,

Unfortunattely I can't help you any furter. All I've done with this library was to connect a card to my Launchpad and make some communication tests.

But in my oppinion your plan has big chances to work.

Success,

Liviu

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

Share on other sites

Hi all,

I have a question that's directed a little more towards the hardware side of interfacing my TM4C123G launchpad with my SD card module using this library. If anyone has any thoughts or ideas, please let me know here: http://forum.stellarisiti.com/topic/2205-help-with-sd-card-module-on-tm4c123gxl/

Thanks so much.

Share on other sites
• 2 months later...

Hello, I'm also getting the messgage Failed with rc=6, please someone help us out!

Join the conversation

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×

×
• Blog

• Activity

×
• Create New...