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

@@Tridon Welcome to the forum.

Look at the "Hardware Preparation" section in this sd-card interface walkthrough

I wanted to ask how to do I write a data into the SD card as the read write function is not the same as arduino

here is an example code where i want to record the temperature

 

 

Wire.requestFrom(TMP275Address, (byte)2);

  byte tempHighByte = Wire.read();
  byte tempLowByte = Wire.read();
  float temperature = word( tempHighByte, tempLowByte)/256.0;
  lcd.print(temperature);
  int b = 28;
  if (temperature< 
  {
  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  }
  if (temperature >= b, temperature++)
  {
  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  }
  rc = FatFs.open("Temperature.txt");
  FatFs.write(temperature);
 
 
Do I directly write into SD card with the instruction above or am I missing something?
Edited by bluehash
[Admin] Please use code tags next time.
Link to post
Share on other sites
  • 2 weeks later...
  • 2 months later...

Hi,

Im working with msp432 launchpad.There is and error in SPI library.Plese tell what modifications are required to be done for msp432 lauchpad.

 

I'm writing a tutorial on getting the MSP432 Launchpad working with the SDcard reader with full fatFS. I'm almost there. 

 

msp432_launchpad_sdCard_fatfs.jpg

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

Hi,

 

I'm trying to use an SDCard as a datalogger. I can write to the card using the sample. I want to append the data and for that I'm using a 4 byte header in the file. It seems that when I want to update the header after a logging session all the data is missing from the file as well.

What am I doing wrong:

...
rc = FatFs.open("T_WRITE.TXT");
if (rc) die(rc);
char buffer[4];
rc = FatFs.read(buffer, sizeof(buffer), &br); /* Read a chunk of file */
if (rc || !br) die(rc);         /* Error or end of file */
for (uint16_t i = 0; i < br; i++){
            fileIndex.myByte[i]=buffer[i];        
}
rc = FatFs.lseek(fileIndex.myLong+4);
if (rc) die(rc);
        
        for (uint16_t i=0;i<20;i++) {
        // simulate write of data
          int val[4];
          val[0]=random(2000);
          val[1]=random(2000);
          val[2]=random(2000);
          val[3]=random(2000);
          String reading;
          reading+=val[0];
          reading+=" ";
          reading+=val[1];
          reading+=" ";
          reading+=val[2];
          reading+=" ";
          reading+=val[3];
          reading+="\n\t";
          char buf[reading.length()];
          reading.toCharArray(buf, reading.length());
          rc = FatFs.write(buf, reading.length(), &bw);
          // update index value

          fileIndex.myLong+=reading.length();
          if (rc) break;
         }
if (rc) die(rc);
rc = FatFs.write(0, 0, &bw);  //Finalize write
if (rc) die(rc);


//update fileindex
rc=FatFs.lseek(0);
rc = FatFs.write(fileIndex.myByte,4,&bw);
if (rc) die(rc);
rc = FatFs.write(0, 0, &bw);  //Finalize write
if (rc) die(rc);
rc=FatFs.close();
if (rc) die(rc);

Serial.println();
Serial.print("Test completed.");

regards

 

Bob

 
Link to post
Share on other sites

Not sure what you are trying to do.. but there is an example here:

http://elm-chan.org/fsw/ff/pf/lseek.html

I don't want the data to be overwritten every time I open the file for logging. So that's why I thought to add the current size of the data as a 4byte header of the file that I read every time the file is opened.

That's the first lseek.

Then I write the data and keep track of the size of the data output to the file. After the data is logged I have to update my file header. So I do an lseek(0) to rewind. There things seem to go wrong because I end up with an updated header and an emtpy file.

If I do not update the file header the data is in the file. It seems that the data is not written to the sdcard before the rewind.

Link to post
Share on other sites
  • 5 months later...
  • 6 months later...

Has anyone tested the code uploaded by CalinP (see #15  Feb 21, 2013) recently?

 

I am using Energia 1.6.10E18 running on a MAC OS X.  

 

All I did was the following:

 

1. Downloaded the code and place the entire folder into the Energia folder.

2. I then opened the example "PFATFsFileTest" and clicked on "verify" to make sure it would compile....and of course it did not. 

 

Here is the debug info. 

 

 

In file included from /Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:23:0,

                 from /Users//Documents/Energia/PFatFs/examples/PFatFsFileTest/PFatFsFileTest.ino:9:
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:57:3: error: expected unqualified-id before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:57:3: error: expected ')' before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:95:25: error: expected primary-expression before ',' token
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:95:27: error: expected primary-expression before 'const'
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:95:38: error: expression list treated as compound expression in initializer [-fpermissive]
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:96:25: error: expected primary-expression before ',' token
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:96:34: error: expected primary-expression before '*' token
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:96:35: error: expected primary-expression before ')' token
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/utility/pff.h:96:35: error: expression list treated as compound expression in initializer [-fpermissive]
In file included from /Users/chrispinter/Documents/Energia/PFatFs/examples/PFatFsFileTest/PFatFsFileTest.ino:9:0:
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:37:11: error: expected unqualified-id before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:37:11: error: expected ')' before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:81:19: error: expected identifier before '(' token
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:81:19: error: expected ')' before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:81:19: error: expected ')' before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:81:19: error: expected ';' at end of member declaration
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:81:19: error: expected unqualified-id before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:84:19: error: expected identifier before '(' token
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:84:19: error: expected ')' before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:84:19: error: expected ')' before numeric constant
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:84:19: error: expected ';' at end of member declaration
/Users//Documents/Energia/libraries/SDCardTutorialWithEnergia/pfatfs.h:84:19: error: expected unqualified-id before numeric constant
PFatFsFileTest:17: error: expected unqualified-id before numeric constant
PFatFsFileTest:17: error: expected ')' before numeric constant
/Users//Documents/Energia/PFatFs/examples/PFatFsFileTest/PFatFsFileTest.ino: In function 'void loop()':
PFatFsFileTest:108: error: 'dir' was not declared in this scope
exit status 1
expected unqualified-id before numeric constant
 
....
 
I think the current version of Energia might not like the DIR or FILE.   These variables are causing me grief.  Is there a bug to fix, work around, or a better way to do this?
 
Thanks,
 
Spineless
Link to post
Share on other sites

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