Shop OBEX P1 Docs P2 Docs Learn Events
Problem writing to SD card — Parallax Forums

Problem writing to SD card

HughHugh Posts: 362
edited 2009-07-11 15:58 in Propeller 1
Folks,

I'm trying to write to an SD card using the excellent fsrw object, but am having some problems.

OBJ
  sdfat         :               "fsrw"  
  lcd            :               "LCD"

VAR

Byte mode, index, fast, tRef, recData[noparse][[/noparse]100] , AnsaA [noparse][[/noparse]25], tbuf[noparse][[/noparse]20], r,  sta
long txDisp, units ,  AnsaB, Ansa, stack1[noparse][[/noparse]20], stack2[noparse][[/noparse]20], stack3[noparse][[/noparse]20]



pub main   

    waitcnt(80_000_000 + cnt)
    sdfat.mount(00)

    AnsaA:=string("Test")               ' What I am trying to write to the SD card




  
   lcd.cls
   if r ==0
      lcd.str(string("Mounted."))
      waitcnt(240_000_000 + cnt)  
      sdfat.opendir
      repeat while 0 == sdfat.nextfile(@tbuf)
            sta := cnt
   else
     lcd.str(string("Failed!"))

  sdfat.popen(string("Data1.csv"), "a")

   repeat 500
      ct :=0
'      repeat 20                        
'          sdfat.pputc(AnsaA[noparse][[/noparse]ct++])                 This didn't work
      
     sdfat.pwrite(@AnsaA,25)
     sdfat.pputc(13)                                 'Carriage Return

  sdfat.pclose




What I get is a file with 500 "œ" characters, each with 25 spaces before them. I'm obviously making a fundamental mistake here, but can't see the wood for the trees.

Any suggestions / pointers would be gratefully received - I have been through the 'insert SD card - turn on Prop - upload code - wait for it to mount / write - turn off Prop - remove SD card - insert SD card in PC - open file - close file - alt-tab to Prop tool - change code' loop so many times now!

Many thanks,

Hugh

P.S. Its an OBD code reader for my Saab that shows live data on an LCD display - I want to log one or two parameters to SD every couple of seconds.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-11 15:58
    1. AnsaA is already a pointer, so don't use the @ operator in the pwrite
    2. The string is only 4 bytes long, so don't tell pwrite to write 25 bytes.

    pwrite(AnsaA, 4)

    PS:
    Ah ... I see .. you have a big missunderstanding in the string-instruction. string won't copy the string into your array. string stores the string you pass as a parameter somewhere in a dat-section and returns a pointer to that place.

    By the way .. you could also write:
    AnsaA:=string( "Test", 13)

    Then you don't need the putc.

    Post Edited (MagIO2) : 7/11/2009 4:13:23 PM GMT
Sign In or Register to comment.