Shop OBEX P1 Docs P2 Docs Learn Events
SimpleTools Issue — Parallax Forums

SimpleTools Issue

tdlivingstdlivings Posts: 437
edited 2013-05-16 17:41 in Propeller 1
I am getting the output I expect to go to the SD card but instead it goes to the terminal.
This had me going on a program I was working on so I created a test app to help see why.
Thinking it was me but instead there is some is an issue with adding the putchar(CLS) statement.
Everything works fine if you comment out that line, it gets written to the SD card .
At first I thought some how having FILE* and FileName globle maybe but not so.

I am using Steve's(jazzed) serial code however it did work as I said unless you putchar(CLS);

Attached is a zip of the project and a pic of bad output.
/*
 Write a simple comma seperated file to SD Card




*/




#include "simpletools.h"                      // Include simple tools

#include "FdSerial.h"                         // Add Steve(jazzed) FullDuplexSerial C version




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

char myfilename[] = "Data7.csv";

FILE* fp;

int RX = 5, TX = 4;                           // XBEE connected pins







int main()                                    // Main function

{

  int count = 0;

  int yval = 0;




    pause(1000);

    sd_mount(DO, CLK, DI, CS);

    FdSerial_start(RX,TX,0,9600);              // Full Duplex serial to XBEE

    putchar(CLS);         //<<== HAVING THIS LINE CAUSES SD CARD WRITES TO GO TO TERMINAL(stdout I guess)

    fp = fopen(myfilename,"w");




    // Wait for a key to be pressed on the terminal 

    char ch = getchar();




    // Write a text file

    printf("Writing file\n"); 

    for(int idx = 0;idx < 11;idx++) {

      count = idx;

      yval = 10 * count;

      fprintf(fp,"%d,%d\n",count,yval);

      pause(500);

    }

    fclose(fp);

    printf("Done Writing File\n");

    

}


Tom

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-05-16 09:41
    Another issue caused by having Tiny Lib set by default.

    Tiny Lib does not support stdio. Read the tinyio.h file for understanding the limits of Tiny Lib.

    Please uncheck Tiny Lib in the Project Manager -> Linker tab.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-16 12:07
    Steve
    I unchecked it and now all it does is echo what I type on the keyborard to the terminal but does not
    print anything from the rest of the code or do anything with the SD card.
    At first I thought I now needed to add #include "stdio.h" but after doing that and still only echoing to
    terminal I realized simpletools.h was including it and just about everything else already.

    Sorry if I missed some info on building without tinylib,

    Tom
  • jazzedjazzed Posts: 11,803
    edited 2013-05-16 12:40
    It seemed to work for me this morning. I.e. cleared screen, took my input char to start, printed "Writing file", then "Done Writing File". I did not check the SD card contents.

    I had to add the missing FdSerial* header files to the project. If you add the headers to the project, they will be included in the .zip for sharing.

    Can you please "Select All" and Copy/Paste here from the build status so I can see what happened in the build?

    Thanks.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-16 13:12
    Here is the build status

    Project Directory: C:/Users/TDL/Documents/SimpleIDE/My Projects/



    propeller-elf-gcc.exe -I . -L . -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I FdSerial -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c FdSerial.c -o cmm/FdSerial.o

    propeller-elf-gcc.exe -I . -L . -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I FdSerial -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -o cmm/SDWriteTest2.elf -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 cmm/FdSerial.o SDWriteTest2.c -lsimpletools -lsimpletools

    propeller-elf-objdump -h cmm/SDWriteTest2.elf

    Done. Build Succeeded!




    propeller-load.exe -Dreset=dtr -I C:/propgcc/propeller-load/ -b ACTIVITYBOARD -p COM9 cmm/SDWriteTest2.elf -r

    Propeller Version 1 on COM9




    Patching __cfg_sdspi_config1 with 18161701

    Loading cmm/SDWriteTest2.elf to hub memory




    18416 bytes sent




    Verifying RAM ...

    OK

    Also the project file

    SDWriteTest2.c
    -I ../Learn/Simple Libraries/Utility/libsimpletools
    -L ../Learn/Simple Libraries/Utility/libsimpletools
    FdSerial.c -> FdSerial.c
    >compiler=C
    >memtype=cmm main ram compact
    >optimize=-Os
    >-m32bit-doubles
    >-fno-exceptions
    >defs::-std=c99
    >linker::-lsimpletools
    >BOARD::ACTIVITYBOARD
  • tdlivingstdlivings Posts: 437
    edited 2013-05-16 13:20
    As a check I rechecked tinylib in linker to put it back in, commented out putchar(CLS) and it worked

    Here for reference is build status of what worked

    Project Directory: C:/Users/TDL/Documents/SimpleIDE/My Projects/



    propeller-elf-gcc.exe -I . -L . -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I FdSerial -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c FdSerial.c -o cmm/FdSerial.o

    propeller-elf-gcc.exe -I . -L . -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I FdSerial -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -o cmm/SDWriteTest2.elf -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 cmm/FdSerial.o SDWriteTest2.c -ltiny -lsimpletools -ltiny -lsimpletools -lsimpletools

    propeller-elf-objdump -h cmm/SDWriteTest2.elf

    Done. Build Succeeded!



    And the project file

    SDWriteTest2.c
    -I ../Learn/Simple Libraries/Utility/libsimpletools
    -L ../Learn/Simple Libraries/Utility/libsimpletools
    FdSerial.c -> FdSerial.c
    >compiler=C
    >memtype=cmm main ram compact
    >optimize=-Os
    >-m32bit-doubles
    >-fno-exceptions
    >defs::-std=c99
    >-ltiny
    >linker::-lsimpletools
    >BOARD::ACTIVITYBOARD

    -ltiny is back in
    Tom
  • jazzedjazzed Posts: 11,803
    edited 2013-05-16 13:38
    Odd that one build output has "Patching __cfg_sdspi_config1 with 18161701" but the other does not. I don't recall if I saw that this morning or not. Don't see anything else peculiar about the build status output.

    If you don't mind, please put the putchar(CLS); back in, add the headers to the project, un-check tiny lib, re-run, snapshot output, and Zip the project. Also make a zip of the cmm/SDWriteTest2.elf. Post the output snapshot and zips here. I won't be able to check on it until tonight, but someone else with an ACTIVITYBOARD and an SD Card might have time before I can get to it.

    Thanks.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-16 13:53
    OK For your info putchar(CLS) in or out it still only echo's what I type to terminal. It is in for this
    /*
     Write a simple comma seperated file to SD Card
    
    
    
    
    */
    
    
    
    
    #include "simpletools.h"                      // Include simple tools
    
    #include "FdSerial.h"                         // Add Steve(jazzed) FullDuplexSerial C version
    
    
    
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;
    
    char myfilename[] = "MyData2.csv";
    
    FILE* fp;
    
    int RX = 5, TX = 4;                           // XBEE connected pins
    
    
    
    
    
    
    
    int main()                                    // Main function
    
    {
    
      int count = 0;
    
      int yval = 0;
    
    
    
    
        pause(1000);
    
        sd_mount(DO, CLK, DI, CS);
    
        fp = fopen(myfilename,"w");
    
        FdSerial_start(RX,TX,0,9600);              // Full Duplex serial to XBEE
    
        putchar(CLS);         //<<== HAVING THIS LINE CAUSES SD CARD WRITES TO GO TO TERMINAL(stdout I guess)
    
    
    
    
        // Wait for a key to be pressed on the terminal 
    
        char ch = getchar();
    
    
    
    
        // Write a text file
    
        printf("Writing file\n"); 
    
        for(int idx = 0;idx < 11;idx++) {
    
          count = idx;
    
          yval = 10 * count;
    
          fprintf(fp,"%d,%d\n",count,yval);
    
          pause(500);
    
        }
    
        fclose(fp);
    
        printf("Done Writing File\n");
    
        
    
    }
    

    BUILD STATUS

    Project Directory: C:/Users/TDL/Documents/SimpleIDE/My Projects/

    propeller-elf-gcc.exe -I . -L . -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I FdSerial -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c FdSerial.c -o cmm/FdSerial.o
    propeller-elf-gcc.exe -I . -L . -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I FdSerial -I ../Learn/Simple Libraries/Utility/libsimpletools -L ../Learn/Simple Libraries/Utility/libsimpletools/cmm/ -o cmm/SDWriteTest2.elf -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 cmm/FdSerial.o SDWriteTest2.c -lsimpletools -lsimpletools
    propeller-elf-objdump -h cmm/SDWriteTest2.elf
    Done. Build Succeeded!

    Project File contents
    SDWriteTest2.c
    -I ../Learn/Simple Libraries/Utility/libsimpletools
    -L ../Learn/Simple Libraries/Utility/libsimpletools
    FdSerial.c -> FdSerial.c
    >compiler=C
    >memtype=cmm main ram compact
    >optimize=-Os
    >-m32bit-doubles
    >-fno-exceptions
    >defs::-std=c99
    >linker::-lsimpletools
    >BOARD::ACTIVITYBOARD
  • edited 2013-05-16 14:18
    Thanks for bringing this to our attention tdlivings,

    While we look into it, here is something else to try:

    I ran into the same problems with XBee a couple days before you did, but my remedy was slightly different. I took Martin Hebel's XBee object from here:

    http://obex.parallax.com/object/674

    ...and converted it with the spin2cpp tool from here:

    code.google.com/p/spin2cpp

    I'm in the process of making the machine generated function names and parameters more user-friendly, and after that it goes into the Simple Library format, so please keep in mind that it's a work in progress. I'm doing something similar with the SD stuff, and it'll save a lot of program space when it's ready.

    In the meantime, here is in-progress XBee with the current (soon to be replaced) SD in an example. For XBee examples that translate pretty readily to the functions in xb.h, use:

    http://www.parallax.com/portals/0/downloads/docs/prod/book/122-32450-XBeeTutorial-v1.0.1.pdf
    and
    http://www.parallax.com/portals/0/downloads/docs/prod/rf/XBeeTutorialCode.zip

    xb.h has been added as a link in the file manager, so just click the bottom-left Show Project Manager button in Simple View and then click the xb.h link in the file list to view the functions you can use.

    Andy
  • tdlivingstdlivings Posts: 437
    edited 2013-05-16 15:14
    OK
    Andy I will look at it, thank's for posting.
    The issue with XBEE is you need to watch for a char and go back to doing something
    else if one is not there. Actually could also be a menu system that you press a key anykey or
    'Q' say to stop a running operation.
    "C" style stream I/O does not have that ability, I am no expert and am open to someone pointing
    out to me it does. I wondered why I could do it in the past and found it was because on CONIO.H.
    Turns out from some googling CONIOLH is platform specific and not liked by "C" purists.
    However it is available for Windows, and even Linux, and maybe Mac.

    As you saw in my other XBEE experiments I did get fgets() to receive the XBEE text "C" style but
    stream I/O left me with no control and I did not have a warm fuzzy feeling it was even totally working.

    For my XBEE logging experiment I ended up putting a button on the breadboard. Push the button to start logging
    push the button to stop logging. Log what was going on to the terminal to see if action was happening.
    All seemed ok until there was nothing on the SD card and that is when I modified the quick demo I posted
    for someone wanting to know how to write sensor values to SD card and then read into Excel.
    I modified that to add Steve's FDS serial code and that has become the mule this thread is about. Ha

    By the way I like what you are doing with "C", great job and looks like a lot of effort.
    When it went more official last Monday I decided to kick the tires and try somethings

    Tom
  • edited 2013-05-16 16:27
    Yeah, that would be:

    http://forums.parallax.com/showthread.php/147923-SimpleIDE-XBEE-Test

    I want to go back and take a closer look because I did see the same symptom, where fgetc was not fetching any values. I wrote some code that displayed what was in the buffer, so I knew the characters were there. Haven't had time to go back and verify yet. <<<Resolved - see next post.>>>

    Also like yourself, it took some tinkering with the number of characters fread was looking for, at least in XBee command mode. According to the stdio docs fread will return before the number of characters specified if it receives a \n or a 0, but XBee sends a \r. So, one has to know the number of characters in the buffer before calling fread. I experimented with a custom function to check the buffer first and find out how many characters are sitting in there. Although it works, it may not be inline with PropGCC's fdserial's intended use. Have to check on that first.

    In the meantime, it seemed like it would be useful to just port Martin's XBee library, and maybe add a few enhancements to make it more user-friendly than it already is. (Haven't started that part yet. First step is to make the parameters, function names and return values user friendly.)

    Looks like Tiny Lib has quite a few caveats. Since it doesn't support file I/O, I can see how it would redirect the stream to stdout. We might need to go through and uncheck it in all our published examples. Not 100% sure, yet, will have to check with the developers. As Steve said, make sure to uncheck it if you do any file I/O. That would include SD card, Serial LCD example, anything using PropGCC's fdserial, and just about anything that uses fopen, fput, fget, fread, fwrite, and fetc... (That last one isn't a function, it's f followed by etc.)

    Not sure if any of the tweaks I made to the project are useful, but they are attached. I wanted to make sure it was writing and reading, and not exhibiting any more haunted behavior.
  • edited 2013-05-16 17:11
    Well, I went back and took that closer look mentioned in previous post. ...and, the reason you and I were not getting any replies from fgetc was probably because we had Lib Tiny checked. It worked fine as soon as I unchecked it. (Doh!!!) :)

    As always, thank you Jazzed for pointing us in the right direction!

    Test code attached. Make sure to adjust line 49 from ...9, 8... to your XBee DO, XBee DI connections.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-16 17:41
    Andy
    Here are the results of switching my logging program to your new Lib based on Martins OBEX obj.
    First
    I just replaced Steve's serial code with the new lib code, very similar because both are FDS like.
    I left Tiny Lib in and commented out putchar(CLS)
    It worked fine same as it did with Steve' code XBHUM03.TXT is the captured file with data I had to rename them to txt from csv the forum does not like csv

    Second
    I put back in putchar(CLS) and still have Tiny Lib
    What I saw on terminal had lost chars lines had right kind of data but missing at the beginning and end
    However the SD card had no data XBHUM06.TXT , well not exactly no data looking at the file in hex
    reveled several zeros at the beginning of the file .

    Third
    Repeated Second to see if it was a fluke of maybe even the XBEE's talking
    Got same result as second XBHUM07.TXT.
    Again no data on SD card just some zeros

    Fourth
    Same as First putchar(CLS) out just making sure we were still working and nothing else happened
    Looks ok again XBHUM08.TXT

    Fifth
    No Tiny Lib, No putchar(CLS)
    Looks ok logging
    SD card has data

    The forum would not attach 06 and 07 as it saw them with size of 0kb
    The missing numbers in the list of files is because I already had files 04 05 with data on the SD Card with data from logging earlier

    By the way my button is a pull up to 3.3 v and pushing it is grounding the input.
    Actually it is a pullup connected to P0 and a wire I touch to ground. It is a bit quick to react.
    I tried a tack sw but it kept popping off the breadboard.

    Tom
Sign In or Register to comment.