Jump to content
calinp

[Energia Library] Petit FatFS SD Card Library

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

I'm use a pull up resistor (10Kohm or similar) in SCK pin and no more Failed with rc=6.

I don't know the reason for this but working on a TIVA Launchpad.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hi there, I also have a data logging project and need 128GB+ of data storage. Post #54 reported a working 8 GByte SDHC. Does anyone know if Card Reader and Petit FatFS would work with SDXD?

 

Thanks!

Dale

Share this post


Link to post
Share on other sites

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

 

Share this post


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.

Share this post


Link to post
Share on other sites

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

Share this post


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