Jump to content

Recommended Posts

am actually using an example code to write on SD card. on my MSP430FR5994 and its not working. can t someone please help me. the code looks like:


#include "SPI.h" 
#include "pfatfs.h"

#define read_buffer     400        // size (in bytes) of read buffer 
#define LOG_DELAY    3600      
#define detect_pin        25      // sd_detect pin (P7.2)   (P7.2/UCB2CLK )
#define cs_pin            31     // chip select pin (P4.0) (P4.0/A8)
unsigned short int bw, br ,c ;
//char buffer[1];   


char buffer[read_buffer];
int result;
DIR dir;
FILINFO fno;      // file  information 
int count = 0;

void setup ()
{

pinMode(cs_pin, OUTPUT);
pinMode(detect_pin, INPUT_PULLUP);
  Serial.begin (9600);    // initialisation 
  FatFs.begin(cs_pin);   // initialisation PFatFs lib

  Serial.println ();
  Serial.println ("welcome to SD logging");
  Serial.println ("");


  
  result = FatFs.opendir (&dir, "");

  if (result)
{      
      Serial.println("I cannot find the SD card.  Please check the connections."); // sd nicht gefunden
      return;    
}
Serial.println(" SD inhalt: ");

  count = 0;
  for (;;) {
    result = FatFs.readdir(&dir, &fno);    // 
    if (result || !fno.fname[0]) break;   // 
    if (fno.fattrib & AM_DIR) {  // 
      Serial.print("<dir>\t"); 
      Serial.println(fno.fname);  // 
    }
    else {                                    
      Serial.print(fno.fsize);  //  file size 
      Serial.print("\t");   //tabulation
      Serial.println(fno.fname);  // file name
      if (!strcmp (fno.fname, "demo.txt")){
        count = 1;
      } 
    }
  }
   if (result) {  
    Serial.println("Error  of card contents.");
    return;   
  }

  Serial.println("");
  if (count){
    Serial.println("demo.TXT file is present on the card");
  }
  else{
    Serial.println("demo.TXT file is present not  on the card.");
    return;
  }

      Serial.println();
         for (;;) {
   result = FatFs.read(buffer, sizeof(buffer), &br); /* Read a chunk of file */
   if (result || !br) break;      /* Error or end of file */
   for (uint16_t i = 0; i < br; i++)    /* Type the data */
   Serial.print(buffer);

   }
   
   delay(LOG_DELAY);

    Serial.println();

  
  result = FatFs.open("demo.TXT");
  if (result) { 
    Serial.println("Unable to open file");
    return;   
  }

  Serial.println();
  Serial.println("file is being edited.");
 
  bw=1;

  result = FatFs.write(buffer, sizeof(buffer), &bw);

  if (result) {
    Serial.println("Error while writing ...");
    return;  
  }

  result = FatFs.write(0, 0, &bw);  //writting (?)
  if (result) {  
    Serial.println("Error while writing file..");
   pf_write(&c, 1, &bw);
        return ; /* (bw == 1) ? 1 : EOF; */
  }

  result = FatFs.close();   // close file

  if (result) {  
    Serial.println("Error closing file.");
    return;   
  }

}
 

Share this post


Link to post
Share on other sites

By providing that kind of information  nobody will be able to help.

So at least add:

- type of SD card

- connection of sd card

- observed error

- steps you have tried already

- references to the libraries used

Share this post


Link to post
Share on other sites

thank you for an answer I forget to add notification, so I just saw the response. I actually give up  on energia.

am trying the example I saw.Since I don't know much.Here is the issue I have: how else should I define FIL (SD card, SDHC 16GB, using FATFS Lib)

Unbenannt.JPG

Unbenannt1.JPG

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