Thread: Hyperterminal and MPLAB in C

  1. #31
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Writing to SD cards can be frustrating to get going

    Make sure you use the FSIO header file.

    Make sure that the SD card has been formatted

    Showing us some code will also help
    Fact - Beethoven wrote his first symphony in C

  2. #32
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Ok here is the current sample code I am using

    Code:
    #include "main.h"
    #include "events.h"
    #include "init.h"
    #include "task_sd_measure.h"
    // Pumpkin CubeSat Kit headers
    #include "csk_rand.h"
    #include "csk_sd.h"
    #include "csk_uart.h"
    // HCC-Embedded + CubeSat Kit headers
    #include "thin_usr.h"
    // Pumpkin Salvo headers
    #include "salvo.h"
    
    /******************************************************************************
    ****                                                                       ****
    **                                                                           **
    task_sd_measure()
    Report on the size of the CSK_TEMP.TXT file on the card every few seconds.
    **                                                                           **
    ****                                                                       ****
    ******************************************************************************/
    void task_sd_measure(void) {
      F_FILE * file;
      unsigned long size;
      user_debug_msg(STR_TASK_SD_MEASURE "Starting.");
      
     
        // Wait 2.5s + some random time. Avoid 
        //  OS_Delay(0) because that will stop this task.
        OS_Delay(250); 
        OS_Delay(1 + ((csk_rand()>>8)& 0x007F));
        
        // Acquire SD Card.
        OS_WaitBinSem(RSRC_SD_CARD_P, OSNO_TIMEOUT);
        
        // Open the file, gets its length and report to user.
        file = f_open( STR_FILE_NAME, "r");
        if (file) {
          size = f_filelength(STR_FILE_NAME);
          sprintf(strTmp, STR_TASK_SD_MEASURE STR_FILE_NAME " is %lu bytes long.", size);
          user_debug_msg(strTmp);
        }
        else {
          user_debug_msg(STR_TASK_SD_MEASURE "Cannot Open" STR_FILE_NAME ".");
        }
        
        // Done, release SD Card, repeat.
        f_close(file);
        OSSignalBinSem(RSRC_SD_CARD_P);
        
      } /* while */
     /* task_sd_measure */

    Where str_file_name is defined as csk_temp.txt in another file. The error I think is that the SD Card is not properly formatted. So I am currently awaiting passwords to do so. I created a simple text file on another computer and saved it to the card but in hyperterminal I get the error Cannot Open csk_temp.txt. which is in the program to occur if unable to read the file if my understanding is correct. I am so close to actually writing my own code and greatly apreciate all the replies and the help it has given. I guess my next problem will be to figure out what sort of format the SD card will require? It is just a normal bought in store Lexar brand (if that matters). CLick_here your a life saver by the way! My boss is thouroughly impressed that i am using forums and outside help so thanks to all! Also pumpkin still hasn't given me permission to use their forums... which is disapointing but hey! Cant win em all.

  3. #33
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I created a simple text file on another computer and saved it to the card but in hyperterminal I get the error Cannot Open csk_temp.txt.
    Well that tells me two things.
    1. The card is properly formatted using a file system the host computer knows about. Typically this will be some minor variant of the FAT file system (which is very easy to implement, and many embedded operating systems will be able to mount such cards without difficulty).

    2. You're almost certainly looking in the wrong place.
    > user_debug_msg(STR_TASK_SD_MEASURE "Cannot Open" STR_FILE_NAME ".");
    As well as outputting this information, also output what your program perceives to be the current working directory. You might have written the test file to D:\csk_temp.txt, but as far as your embedded OS is concerned, it might be mounted in a different place.

    For example, on my Linux box, a file in the root directory of a memory card on windows may be D:\csk_temp.txt, but when mounted on Linux, this becomes /media/DEVICE/csk_temp.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #34
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    I understand what your saying Salem. Problem is Im doing all my work on a desktop that doesn't have a SD card reader. So I am using a laptop to do the SD card things and then plugging it into the development board. I feel like there is a problem with the directory though as you said. Also this code is literallly pumpkins I haven't changed and/or created anything but the text files on the SD card. So I'm still thinking (hoping) it is a format issue. How would I change the directory if that was the issue?

  5. #35
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Have you tried writing a file from your embedded system? If not you may want to give that a try. Trying to create an output file can tell you a couple of things. First if the opening succeeds you will be able to tell what the embedded system considers it's working directory. Second if the creating of the file fails then it is a good indication that the problem is else where.

    Jim

  6. #36
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by tzzr101 View Post
    So I'm still thinking (hoping) it is a format issue.
    What is the format type of the card?

    These are possible answers FAT12 or FAT16; not the only possible answers.

    How large is the card?
    Is the card compatible with the MCU hardware and software?

    The embedded product I use requires SD cards that supports the SPI interface; so does the Cube-Sat.
    And, recommends only some brands and models of SD cards.

    Edit: Did you read this pdf; http://www.cubesatkit.com/docs/csk_s...hin_manual.pdf
    It says SPI interface is used by the Cube-Sat.

    Tim S.
    Last edited by stahta01; 02-26-2013 at 10:55 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #37
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > How would I change the directory if that was the issue?
    Start by reading the manual pages for f_open and see where it takes you.
    Most manual pages have a list of related functions which you should explore. Sooner or later, you should stumble upon functions to get/set the current directory.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #38
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    OK jimblumberg not quite sure how to do that.

    and Tim thank you very much! that answered both of my questions. The SD card was just bought at the store its a LExar media 256MB highspeed. So I will research SPI interface to see if this SD card is even correct for our cubesat.

    Salem I am currently struggling with an error with f_open? isn't usually fopen? found little to no information on the underscore version. Wondering if pumpkin has their own way of calling this out.

    Basically I am taking the sample code and trying to recreate and edit it so that it will do a user ask and await for input andf then follow by implementing a function that will produce a file to be loaded onto the SD card as well as print a message saying that it did so on Hyperterminal. Sort of a giant leap from what I am capable of but we will see how it goes. So far only issues being the f_open, f_write F_FILE*file. Also little confused on the different forms of printf, sprintf, fprintf, fscanf, scanf. So I shall research these thouroughly! Thanks again!

  9. #39
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well when you start working on target hardware, then a lot of what is the standard API could be missing (or renamed).

    Things like strcpy and sprintf are likely to remain the same, they only involve memory.

    But anything involved in talking to devices can have some unique vendor twist.

    Finding the manuals for these f_ functions should be a priority.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #40
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    I honestly cannot find anything on f_open, f_ anything.

    Only fopen, with no underscore.

  11. #41
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Do you know where all the target header files (like csk_sd.h) are stored on your host development environment?

    Doing some kind of "find all files containing f_open" in the 'root' directory of your include files will at least tell you which .h file(s) the function is declared in.

    Knowing this, you can open and inspect those files with a text editor.
    Typically, each function will have a comment briefly outlining the function.

    Since all the f_ functions are likely to be in one place, finding useful related functions should be easy.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #42
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    OK jimblumberg not quite sure how to do that.
    Read the documentation for the fopen() function. You should have documentation for this function in your compiler documentation.

    How are you getting this program to your embedded system so it can run it?


    Jim

  13. #43
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Yes I have all the header files it is all one big sample project. I think I need to just change the f_open to fopen. I'll play around with it a little more to see if I can get it to run as suppossed to.

    Jim, from my understanding in the code pasted above it is going in and reading the file on the SD card and measuring its length? But the problem is that it either cant find the file or can't find the SD card itself. So i am unsure of which of the two it is. Still can't reformat the SD card either awaiting administrative password or right to do so.

  14. #44
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I put "csk_sd.h " into Google and found
    http://www.cubesatkit.com/docs/csk_s...hin_manual.pdf

    Is that what you are using?
    Fact - Beethoven wrote his first symphony in C

  15. #45
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Also, sd libraries usually have an initialisation routine which you have to run before using the library.

    Check to see if there is one in the csk_sd library.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 08-02-2012, 06:15 PM
  2. how its done(hyperterminal)?
    By stefan63 in forum Windows Programming
    Replies: 17
    Last Post: 03-25-2011, 04:24 AM
  3. mplab ide
    By russ4789 in forum C Programming
    Replies: 0
    Last Post: 03-29-2009, 09:05 AM
  4. C30 Compiler for MPLAB
    By Dukefrukem in forum C Programming
    Replies: 1
    Last Post: 11-08-2007, 07:40 PM
  5. Hyperterminal????
    By gvector1 in forum C# Programming
    Replies: 3
    Last Post: 01-22-2004, 08:54 PM

Tags for this Thread