Shop OBEX P1 Docs P2 Docs Learn Events
Writing to SD card problem (solved) — Parallax Forums

Writing to SD card problem (solved)

xanaduxanadu Posts: 3,347
edited 2017-07-06 16:46 in Propeller 1
I'm running the "SD Datalogger.c" that comes with Simple IDE, unmodified. The pic attached shows the expected input, and reads it back correctly.

The problem I have is using my PC/notepad to read the contents of test.txt file on the SD card -
         (   2   

I tried a couple of cards, formatting them fat32. Is there something I need to change to show dec values?
618 x 607 - 43K

Comments

  • the code
    /*
      SD Datalogger.side
    
      Application prompts you to type numbers into SimpleIDE Terminal, and
      records to SD.  Plays back all numbers after you type q and press Enter.
      
      http://learn.parallax.com/propeller-c-simple-devices/sd-card-data
    */
    
    #include "simpletools.h"                      // Include simpletools header    .
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;      // SD card pins on Propeller BOE
    
    int main(void)                                // main function
    {
      print("Enter several values.\n\n");         // User instructions
      print("To see logged values, press\n");
      print("Enter a second time.\n\n");
    
      sd_mount(DO, CLK, DI, CS);                  // Mount SD card
    
      FILE* fp = fopen("test.txt", "w");          // Open a file for writing
    
      int n, status;                              // Number & status variables
      while(1)                                    // Endless loop
      {
        print("> ");                              // User prompt
        status = scan("%d", &n);                  // Get number & status
        if(!status) break;                        // Status 0? Break out of loop
        fwrite(&n, 4, 1, fp);                     // Write number to SD card
      } 
      fclose(fp);                                 // Close the file
      
      print("\nYou entered:\n");                  // List heading
    
      fp = fopen("test.txt", "r");                // Open a file for writing
      while(1)
      {
        status = fread(&n, 4, 1, fp);             // Read from SD & get status
        if(!status) break;                        // If no more, break loop
        print("n = %d\n", n);                     // Display value
      } 
      fclose(fp);                                 // Close the file
    }   
    
  • Never mind, I have it working in SPIN and that is what I should be using anyway.
Sign In or Register to comment.