Shop OBEX P1 Docs P2 Docs Learn Events
SDcard and Propeller — Parallax Forums

SDcard and Propeller

rkrasowskirkrasowski Posts: 16
edited 2011-02-08 15:59 in Propeller 1
Hello,
I am trying to create log, that will be logging temperature, pressure, GPS data etc. Plan is to send data to main computer using XBee as well as record it into SD card connected with Propeller.
Sadly I have a problem at the beginig of working with SDcard. I am using following code:

"
OBJ
sdfat : "fsrw"
db : "FullDuplexSerial"
PUB main | gmt, r
db.start(31,30,0,9600)
db.str(string(13,"Will try to mount SDCard",13))

if \sdfat.mount(3) <> 0
db.str(string(13,"Failed to mount SD"))
sdmounted := 0
else
sdmounted := 1
db.str(string("Mounted.", 13))
"
and I can not mount the card, I am getting message "Failed to mount SD".
I am using Propeller Demo board with micro-SD Card Adapter. My SD card has 2Gb and is formatted in FAT16. My base code is from book "programming and customizing the multicore propeller microcontroller". Source code : ftp://ftp.propeller-chip.com/PCMProp/Chapter_09/Source/
My SDcard connect:
P0 - DO
P1 - CLK
P2 - DI
P3 - CS

What is the problem??
Thanks in advance
Robert

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-06 13:46
    The problem is your sdfat.mount call. The value passed there is the 1st pin of a group of 4, not the last pin. For your connections (P0-P3 = DO/CLK/DI/CS), you should use sdfat.mount(0)
  • rkrasowskirkrasowski Posts: 16
    edited 2011-02-06 14:11
    Hi Mike,
    thanks like always
    Well even before I tried " if \sdfat.mount(0) <> 0"
    No luck, still can not mount
    Any ideas??
    Robert
  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-06 14:23
    The change I mentioned should work. Check your wiring. Reformat your SD card. The current FSRW 2.6 should work whether the card is FAT16 or FAT32. Make sure the 3.3V and Ground connections are correct.

    In the future, please use the [ CODE ] and [ /CODE ] brackets around your code. Cutting and pasting causes your code formatting to be lost. With Spin, it's impossible to tell how your program works unless you use the brackets.
  • rkrasowskirkrasowski Posts: 16
    edited 2011-02-06 14:52
    Ok, it works,
    I upgraded to new ver of FSRW (2.6) and now it works !!!
    Thanks Mike again
    Robert
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-02-06 15:40
    rkrasowski: Robert, welcome to the prop and this fantastic forum. As you can see, help is usually pretty quick here and the prop is a great chip.
  • rkrasowskirkrasowski Posts: 16
    edited 2011-02-06 18:53
    Yep, it took 15 min for Mike to respond :), great ......
    I am making progress with my project, now I am stuck on adding data into the file on SDcard. Now everytime propeller is power on , starts routine and start writting ( and erasing data) into the same file, I am sure there is a method for writting, reading and adding.
    Is it insteed of:

    sdfat.popen(string("newfilexr.txt"), "r") - writting


    sdfat.popen(string("newfilexr.txt"), "a") - adding

    just guessing, I have not tested this yet.

    Robert
  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-06 19:01
    Consider switching to Kye's SD card library (here). It supports appending to an existing file. It also handles subdirectories which FSRW does not.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-02-06 19:14
    Agree'd! I just switched with one of my projects tonight. Subdirectories are a godsend!

    Kye's SD routines aren't too much different in the way they handle. If you can do fsrw, you can handle the switch.

    OBC
  • rkrasowskirkrasowski Posts: 16
    edited 2011-02-08 10:37
    So far I am working with FSRW
    I am analizing all methods and I do not see method to put decimal value into the SDcard. Old ver had something like SDStr, SDdec, SDhex. Ver 2.6 does not have it. I see pputs ( i uderstand this is for string)
    I see pputc, but how do I write dec value??
    Thanks like always
    Robert
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-02-08 12:44
    I don't remember is FSRW has a dec method. If not, take a look at FullDuplexSerial and use a similar method of converting a decimal number to ASCII characters.
  • rkrasowskirkrasowski Posts: 16
    edited 2011-02-08 15:59
    Thanks for idea and help. I simply copied method SDdec form old version of FSRW that allows put decimal values into SDcard and it works :)
    Here is the code if anyone needs it:
    [
    PUB SDdec(value) | i

    if value < 0
    -value
    pputc("-")
    i := 1_000_000_000
    repeat 10
    if value => i
    pputc(value / i + "0")
    value //= i
    result~~
    elseif result or i == 1
    pputc("0")
    i /= 10
    ]

    also answering my previous question, FSRW can add data to file. Here is the code to open file for adding :

    [
    sdfat.popen(string("newfilexr.txt"), "a")
    ]

    Thanks again for yopur help.
    Robert
Sign In or Register to comment.