Jump to content
bluehash

PetiteFS FATfs SDCard USCI code

Recommended Posts

Blue Hash, 

I proceed to some modification to write in SDcard , i will share my code hoping someone can help me.

I connect the msp430g2553, with a sdcard and a LCD, he can mount the card and recognize the disk, but do not write in the file.

Share this post


Link to post
Share on other sites

Friends

I need some help,using the petitFAT library, I managed to do the implementation in my application, but I need your help to get write to the memory card thing that I am not able to do. Can anyone help me? 

Did you follow the tutorial here. You need to create the file on the card first.

Share this post


Link to post
Share on other sites

Hello Bluehash, I follow the tutorial,  and everything seems to be ok, the file was created earlier on the card. 

The problem is that does not write on the card, I shared all my file and picture of what happens to me, hoping to get some help, that would allow me to solve the problem.

Share this post


Link to post
Share on other sites

@@bluehash I try to write my data into SD-card, but i have a problem. It overwrite the old-data in sd card, i try to using "pf_lseek(ofs);" function, but nothhing change and i can't control the pointer where i start to write the first data. And further, i can read- write data correctly without control the first byte location. Where is the mistake? Please help me!

And my project in the attach file.

Thank you!

test sd card 3.rar

Share this post


Link to post
Share on other sites

@@bluehash I try to write my data into SD-card, but i have a problem. It overwrite the old-data in sd card, i try to using "pf_lseek(ofs);" function, but nothhing change and i can't control the pointer where i start to write the first data. And further, i can read- write data correctly without control the first byte location. Where is the mistake? Please help me!

And my project in the attach file.

Thank you!

Help me, please! :sad:

Share this post


Link to post
Share on other sites

Hi ,
I testing this library with the MSP430FR4133 LP and my own code.. the Read and Write function is working fine, But the Thing is while writing to a file only Five characters is getting written to the file i.e if I write KAMALESH only KAMAL is written to the file. Can you Help me with this issue..

Source Code


#include <SPI.h>
#include <pfatfs.h>
#include <pffconf.h>

#define cs_pin      8             // chip select pin 
#define read_buffer 128             // size (in bytes) of read buffer 
#define LOG_DELAY   5000          // 5000ms -> 5sec

unsigned long int bw, br;//, i;
char buffer[read_buffer];
int rc;
DIR dir;        /* Directory object */
FILINFO fno;      /* File information object */

uint32_t ui32_ReadTemp = 0;
uint8_t StringLength = 0;
char buf[30];
uint32_t counter = 0;
uint32_t AccStringLength = 0;

void setup()
{
   Serial.begin(9600);                // initialize the serial terminal
   analogReference(INTERNAL1V5);
   FatFs.begin(cs_pin);              // initialize FatFS library calls
   Serial.print("\n\n\nMSP430 Logger \n\r"); 
   Serial.println("Type the String");
}
         
/* Stop with dying message */         
void die ( int pff_err  )
{
   Serial.println();
   Serial.print("Failed with rc=");
   Serial.print(pff_err,DEC);
   for (;;) ;
}

void printDec(uint32_t ui) 
{
   Serial.print(ui/10, DEC);
   Serial.print(".");
   Serial.print(ui%10, DEC);
}

/*-----------------------------------------------------------------------*/
/* Program Main                                                          */
/*-----------------------------------------------------------------------*/
void loop()
{
if(Serial.available())
{
  String src = Serial.readString();

  if(src.indexOf("R") != -1)
  {
      rc = FatFs.open("datalog.txt");
      if (rc) die(rc);
      delay(100);
      for (;;) {
      rc = FatFs.read(buffer, sizeof(buffer), &br);  /* Read a chunk of file */
     if (rc || !br) break;      /* Error or end of file */
     Serial.println(buffer);
       rc = FatFs.close();  //Close file
     if (rc) die(rc);
     }
  }
  else
  {
    rc = FatFs.open("datalog.txt");
    if (rc) die(rc);
   delay(100);
  char* msg = string2char(src);
      StringLength =  strlen(msg);
      Serial.println(msg);  
Serial.print("Size:");
Serial.println(StringLength);
      rc = FatFs.write(msg, StringLength,&bw);
      if (rc) die(rc);
      // rc = FatFs.write(0, 0, &bw);  //Finalize write
      // if (rc) die(rc);
       rc = FatFs.close();  //Close file
            if (rc) die(rc);
       Serial.println("ADDED");
    }
  }
}

char* string2char(String command)

  if(command.length()!=0)
  { 
    char *p = const_cast<char*>(command.c_str()); 
    return p;     
  }
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×