Shop OBEX P1 Docs P2 Docs Learn Events
Trouble with SD Card tutorial — Parallax Forums

Trouble with SD Card tutorial

IamretiredIamretired Posts: 56
edited 2013-05-14 16:46 in Learn with BlocklyProp
I was able to run the first example, but not the second.
The second example requires modifications to the first.
The code below includes the changes required.
When I make the changes, I get errors.

/* SD Card Data tutorial
http://learn.parallax.com/propeller-c-simple-devices/sd-card-data
*/

#include "simpletools.h"

int DO = 22, CLK = 23, DI = 24, CS = 25;

int main(void)
{
pause(1000);

sd_mount(DO, CLK, DI, CS);

FILE* fp = fopen("test.txt", "w");

int val = 500; //1 <- add
fprintf(fp, "%d\n", val); //2 <- modify
val = -1000000; //3 <- add
fprintf(fp, "%d\n", val); //4 <- add
fclose(fp);

char s[15]; //5 <- remove
fp = fopen("test.txt", "r");
fread(s, 1, 15,fp); //6 <- remove
//fscanf(fp, "%d", &val); //7 <- add
//printf("val = %d\n", val); //9 <- add
//fscanf(fp, "%d", &val); //9 <- add
//printf("val = %d\n", val); //10 <- add
fclose(fp);

printf("First 21 chars in test.txt:\n"); //11 <- remove
printf("%s", s); //12 <- remove
printf("\n"); //13 <- remove

}
/*
With adds and modify //1 to //6 and removes //11 to //13
not done the following is displayed on terminal window.

First 21 chars in test.txt:
500
-1000000


When adds, modify and removes are done the program will
not compile.
*/

I have looked it over for keying errors and can't find any. I don't know if the code in the
tutorial works or not: I can't copy it to SimpleID to try it.

Please excuse the formatting: I tried to add spaces so that the '//#' line references would
be easier to see. Oh well.

Any ideas?
Johnmb

Comments

  • RaymanRayman Posts: 14,640
    edited 2013-05-14 13:40
    If it won't compile, it should tell you which line number is the problem...
    Do you see that?
  • edited 2013-05-14 13:41
    Will test it, back in a few...
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2013-05-14 13:49
    I am new to all of this, learning as I test-drive and format the tutorials. I will re-run that tutorial and see if I inadvertently introduced an error in the example part.
  • edited 2013-05-14 14:01
    Hmmm, copied and pasted your code over a Save Project As of SD Minimal.side, and then un-commented the lines you added, and re-commented the lines you took out. So, it looks like this (below with a little extra formatting). No compiler errors, and output was correct.
    #include "simpletools.h"
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;
    
    int main(void)
    {
      pause(1000);
    
      sd_mount(DO, CLK, DI, CS);
    
      FILE* fp = fopen("test.txt", "w");
    
      int val = 500;                                    //1 <- add
      fprintf(fp, "%d\n", val);                       //2 <- modify
      val = -1000000;                                //3 <- add
      fprintf(fp, "%d\n", val);                       //4 <- add
      fclose(fp);
    
      //char s[15];                                     //5 <- remove
      fp = fopen("test.txt", "r");
      //fread(s, 1, 15,fp);                            //6 <- remove
      //fscanf(fp, "%d", &val);                     //7 <- add
      printf("val = %d\n", val);                     //9 <- add
      fscanf(fp, "%d", &val);                       //9 <- add
      printf("val = %d\n", val);                     //10 <- add
      fclose(fp);
    
      //printf("First 21 chars in test.txt:\n");     //11 <- remove
      //printf("%s", s); //12 <- remove
      //printf("\n"); //13 <- remove
    
    }
    


    attachment.php?attachmentid=101599&d=1368565661

    BTW, To start and stop code formatting, use the word code between square brackets [ ]. To end a code snippet, use /code between square brackets.
    563 x 175 - 70K
  • dgatelydgately Posts: 1,630
    edited 2013-05-14 14:02
    I got a compile and run, mod'ing your code with the changes...

    BuildSDTest.png


    What are the compiler errors? You can Right-Click (Control-Click on a Mac) in the compiler 'Build Status' area to select and copy the error log. You may need to click on the Hammer icon near the bottom of the editor to see the Status view.

    That will help in debugging what's wrong.


    Thanks,

    dgately
    972 x 874 - 195K
  • edited 2013-05-14 14:15
    Thanks dgately. Yes, iamretired, please try that and paste the compiler errors into a post; it'll really help identify the bug.
  • IamretiredIamretired Posts: 56
    edited 2013-05-14 15:18
    When I attempt to copy and paste the error, I get the following: ????

    #include "simpletools.h"

    int DO = 22, CLK = 23, DI = 24, CS = 25;

    int main(void)
    {
    pause(1000);

    sd_mount(DO, CLK, DI, CS);

    The error message ( typed ) is:

    region 'hub' overflowed by 868 bytes

    Done. Build Failed!

    Your program is too big for the memory model selected in the project.
  • Jen J.Jen J. Posts: 649
    edited 2013-05-14 15:24
    Moving this thread to the 'Education' forum.
  • edited 2013-05-14 15:37
    Hmm, sounds like your memory model might be LMM for some reason. Click bottom-left Show Project Manager Button. Then, change Memory Model field from LMM Main RAM to CMM Main RAM Compact. It reduces program size significantly with little or no execution speed penalty. Although the stdio library still takes up some space, I've added a lot of code on top of these examples, but only observed small increments of additional memory used.

    Andy
  • IamretiredIamretired Posts: 56
    edited 2013-05-14 16:13
    The project options are 'CMM Main Ram Compact' and '-Os Size'.
    The compiler options are '32bit Double' and '-stdc99'
    The Linker options are 'Mathlib' and '-lsimpletools'
  • edited 2013-05-14 16:15
    Uncheck Math Lib.
  • IamretiredIamretired Posts: 56
    edited 2013-05-14 16:46
    Unchecking Math Lib corrected my problem. Thank you for your time and help. I thought I had tried 'all' combinations.

    Johnmb
Sign In or Register to comment.