+ Reply to Thread
Results 1 to 14 of 14

Thread: SD Card

  1. #1

    Default SD Card

    I'm using the SD Card object to write sensor signals to. Although every once in a while I get an error and I have to stick the SD card in my computer and fix it. Is there a way the Propeller can preform this? For example:

    Code:
    PUB main | errorNumber, errorString
    
      Ser.start(31,30,0,115200)   
        waitcnt(clkfreq * 3 + cnt)
    
        fat.fatEngineStart( _dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, {
                                    } _rtcdatpin, _rtcclkpin, _rtcbuslck)
                                    
        cog := cognew(Get_Data, @stack[0])
        cognew(Display, @stack[150])
        
        dira[9] := 1
        outa[9] := 1
                                    
        errorString := \code ' Returns the address of the error string or null.
        errorNumber := fat.partitionError ' Returns the error number or zero.
        
        if(errorNumber) ' Light a LED if an error occurs.
          outa[23] := 1
          dira[23] := 1
          fat.unmountPartition
          fat.formatPartition(0)
          reboot
    
      repeat ' Wait until reset or power down.
    where the IF errorNumber statement should light an LED to signify there is an error, then unmount partition, format it, and reboot. I've tried this yet it didn't work, it just kept rebooting. I know all the other code works fine.

    I basically want the Propeller to fix the SD card in case there is a power failure during a write command.

    This is my first time using the SD card driver. Any help will be appreciated.

  2. #2

    Default Re: SD Card

    I think you should rather find out what the real problem is. Up to now I found SD card access being very reliable. So, what can cause problems during write?
    1. No cap in the power supply of the SD card or value to low
    2. SD card waering out

    What to do in case one is easy.
    For case 2:
    Is it an old card or a card from a bad brand? Then change the card.
    Maybe you should change the handling of the card? For example if you copy the content daily and immediately delete the file, some sectors are very often used, which increases the speed of wearout. So, fill the card until it's nearly full. (Read acces is not a problem.)

  3. #3

    Default Re: SD Card

    There is no simple way to do what you want. You're looking for a Propeller version of something like Windows' CHKDSK program which reads through the directories and FAT on the SD card looking for errors, then trying to fix any errors found. It's a complicated process, particularly if you want to try to keep as much of the data as possible.

    If you just want to erase the whole SD card and start over, you might want to stop the FATEngine and restart it from the beginning (call FATEngineStart), then try formatPartition. You also may want to display the actual error number and error string to get more information on why the formatPartition fails.

    As MagIO2 suggested, you might spend your time better increasing the capacity of your power supply to handle power failures and sensing when the power begins to fail so your program can stop writing to the SD card while there's still enough power for the card to complete the writes of what's already in its buffers.

  4. #4

    Default Re: SD Card

    Thank you for the reply.

    It's a brand new card.

    I have to admit I didn't clarify in the first post (the power failure was a poor example). Let's say I'm writing some code, I load it to the Prop and it gives me an SD card error. I look at my code and notice one little problem, fix it and reload it. Yet it won't work unless I pull the SD card out and let the computer fix it. Basically I'm getting tired of always have to switch the SD card back and forth from the computer to the Prop.

    Could I reformat the SD card at every start-up of the Propeller? At the moment I don't need old data on it so losing data isn't a problem, its the new data I want.

    EDIT: I'll try the format suggestion, thanks Mike.

  5. #5

    Default Re: SD Card

    It depends on what's broken on the SD card. If the partition table has gotten corrupted, you'll have to do a complete format on your computer. If you read the description of formatPartition in the application note, you'll see that it's really an "erase partition" function. It won't really reformat the SD card. There's no program currently for the Propeller that will do that for you.

    formatPartition is useful if you have a program that creates lots of files or files and subdirectories and you want to get rid of all of them at one time.

  6. #6

    Default Re: SD Card

    Yeah I just read through it. It seems to work a little better now though.

    I replaced the mountPartition() command with the formatPartition().

    what is the fileSize value? bit, byte, kilo, mega, giga.....

  7. #7
    Cluso99's Avatar
    Location
    Sydney/Brisbane Australia or 'sailing on the high seas'
    Posts
    9,974

    Default Re: SD Card

    Not sure if this may help..
    In ZiCog we setup a big file to handle each disk. This way, we just use direct sector addressing and therefore the partition table is never changed. However, there is a gotcha because we rely on the file being contiguous because in reality we access the file as a relative sector from the first sector of the file. Of course, you would need to know where the eof was, or you could just write blanks to it each time you initialise.

    However, this does not solve what is causing your problem. SD cards should have a 10uF tantalum and 0.1uF bypass caps at the socket connector on the pcb.
    My Prop boards: CpuBlade, TriBlade, RamBlade, www.clusos.com
    Prop Tools (Index)
    Emulators (Index) ZiCog (Z80)
    Prop OS (also see Sphinx, PropDos, PropCmd)

  8. #8

    Default Re: SD Card

    I don't think the format command is going to do you much good.

    You're using Kye's driver right? Kye said the format command just deletes the files.

    I've also had SD cards that needed to be reformatted to work properly with Kye's driver. I've also found the "quick format" option doesn't fix the problems.

    I'll need to add a bypass capacitor as others have suggested (though I haven't had trouble recently).

    Duane

  9. #9

    Default Re: SD Card

    Thanks for all the suggestions.

    I think I will have to follow what Mike and MagIO2 suggested, creating some safety nets. i.e.- "low power or something big is about to happen, quick stop writing!"

    I have switched it back to just mounting the partition. I think it was having problems overwriting existing files, not too sure, but the fix is already what I planned on doing. Each cycle a new file is created so a complete archive will be available instead of overwriting the 1 file every time. Having the archive is much more pleasing as this project is something of a historian. Recording signal data over a period of months....I still have to do power requirements, but if all else fails I'll use wall outlets.

    @Duane - Yes, I am using Kye's new SD driver.

  10. #10

    Default Re: SD Card

    SD cards are basically very unreliable.
    Last year I had a 2GB card that suddenly decided that some of it's blocks were write protected despite the fact I never asked for such a thing.
    Searching around on the net and asking on the forum here never produced an answer to that problem.
    This week I have a brand new Kingston uSD card that is unreadable with "dd" under Linux.
    It's hopeless.

  11. #11

    Default Re: SD Card

    I use a SD card for data collection with my day job (chemist). I always have a second recording system running.

    Right now I'm using an USB thumb drive on the board (Propeller Proto) attached to the equipment. The same board transmits the data across the room to a second(Propeller Proto) board that records the data on a SD card and displays the data on a TV screen. Both boards have UPS. It is now very rarely lose data.

    I keep the last file's name in EEPROM so my program can use a new name on each file. Adding this data logging ability has made my life a lot easier.

  12. #12

    Location
    Where everyone+dog take holidays in this beloved country
    Posts
    2,093

    Default Re: SD Card

    Sorry to maybe highjack the thread but I have a question regarding low-level access to the SD... is it ok to toggle CS between bytes when the card is accessed or should it remain selected during the whole transaction ?
    Thanks

  13. #13

    Default Re: SD Card

    @ Ale - Must remain asserted during the whole transaction. Some, cards are more flexible than others about this.

    @th3jester - Um... what you are asking can easily be done. Its mainly just how to code it. All the function calls you need are there.

    You shouldn't have to worry about partition information corruption too much using my driver if the physical link is reliable. But, that must be the case. If your SD card loses power or browns out during operations no coding will help. Other that that. You can write a complex error handling system to take account of all the files and folders on the SD card and decide what to do with them. If you've read the application note on parallax semicondcutor you should be able to understand what to do.
    Last edited by Kye; 05-15-2011 at 10:26 PM.
    Nyamekye,

  14. #14

    Location
    Where everyone+dog take holidays in this beloved country
    Posts
    2,093

    Default Re: SD Card

    Thanks Kye!... that means I have to rethink this circuit...

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 01-22-2011, 04:29 AM
  2. Downloading stored data from an SD card with out removing the card.
    By dodger in forum Propeller 1 Multicore Microcontroller
    Replies: 4
    Last Post: 02-22-2009, 11:16 PM
  3. SD Card interface: Can I read names of files already on card?
    By FlyingFishFinger in forum Propeller 1 Multicore Microcontroller
    Replies: 5
    Last Post: 12-09-2008, 04:22 AM
  4. Replies: 15
    Last Post: 06-29-2006, 03:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts