Shop OBEX P1 Docs P2 Docs Learn Events
Help with writing to SD file please! — Parallax Forums

Help with writing to SD file please!

HughHugh Posts: 362
edited 2009-10-29 15:39 in Propeller 1
Hi folks,

I'm scratching my head and going round in circles - I'll soon be dizzy and bald, so any assistance you could suggest would be gratefully received by me!

I have some data in a variable of up to 40 bytes in length. I can display the contents of the last fifteen bytes (the portion of interest) to an LCD display easily, but I don't seem to be able to write it to a file on an SD card using FSRW v2.4.

The code looks like:

r:=  sdfat.mount(0)
  sdfat.popen(string("Data5.txt"), "a") 
  repeat 11
    lcd.dec(dataIn[noparse][[/noparse]ct - charCtr])                               ' ct = length, so say = 30
    lcd.putc(32)                                                      ' charCtr starts at 15
    sdfat.pputs(num.dec(dataIn[noparse][[/noparse]ct - charCtr--]))
    sdfat.pputs(44)



What actually gets written is ".|.|.|.|.|.|.|.|.|.|.|,"

I have tried without the 'num.dec' (Num = simpleNumbers.spin), using bytemove and pwrite, and many others combinations...

It is probably staring me in the face but what am I doing wrong, or not doing?

Thanks

Bald dizzy Hugh

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

Comments

  • HughHugh Posts: 362
    edited 2009-10-28 19:26
    Yes, I've tried sdfat.pputc!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • lonesocklonesock Posts: 917
    edited 2009-10-28 21:05
    Here are a couple of things to try:
    - use the same output from num.dec in the LCD and SD code
    - make sure to close the file when you are done writing...if you power off or unplug the SD card, the FAT table may not be updated.
    - using "pputs(44)" writes a string where the starting pointer address is 44....probably not what you want!
    - verify your pins connecting to the sd card, and check the return value of the mount call.

    check out the following code (I made some guesses about variables and OBJ types):

    OBJ
      sdfat:        "fsrw"
      lcd:          "Serial_LCD"
      num:          "Simple_Numbers"
    
    CON
      ct = 30
      
    VAR
      long dataIn[noparse][[/noparse] 100 ]
    
    PUB test_code | r, strptr, charCtr 
      r:=  sdfat.mount(0)
      sdfat.popen(string("Data5.txt"), "a")
      charCtr := ct 
      repeat 11
        strptr := num.dec(dataIn[noparse][[/noparse]ct - charCtr--])           ' ct = length, so say = 30   
        lcd.str( strptr )                               
        lcd.putc( " " )                                     ' charCtr starts at 15
        sdfat.pputs( strptr )
        sdfat.pputc( "," )
      sdfat.pclose
    
    



    Please let me know if that changes anything.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.

    Post Edited (lonesock) : 10/28/2009 9:10:44 PM GMT
  • HughHugh Posts: 362
    edited 2009-10-28 21:08
    Will do – thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-28 21:08
    For sure, the "sdfat.pputs(44)" has to be "sdfat.pputc(44)" because "pputs" expects the address of a string (byte array).

    What shows up on the LCD?

    Don't forget that you have to close the file after you finish writing or the last 512 byte block won't be written to the SD card.
  • HughHugh Posts: 362
    edited 2009-10-29 07:18
    Thanks chaps.

    Lonesock's code as above results in a series of what I would call 'high ASCII' characters being displayed on the LCD - if I display them using...

    lcd.dec(dataIn[noparse][[/noparse]ct - charCtr--])          
    

    ...they display correctly. Sometimes "data6.txt" is an empty file.

    A different procedure in the same code writes various data to a file on the SD card without a problem.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • lonesocklonesock Posts: 917
    edited 2009-10-29 15:39
    Hugh said...
    Thanks chaps.

    Lonesock's code as above results in a series of what I would call 'high ASCII' characters being displayed on the LCD - if I display them using...

    lcd.dec(dataIn[noparse][[/noparse]ct - charCtr--])           
    
    


    ...they display correctly. Sometimes "data6.txt" is an empty file.

    A different procedure in the same code writes various data to a file on the SD card without a problem.
    Hmm, if displaying the same string on the LCD doesn't work, maybe something is wrong in the num.dec function? Can you connect up a TV or VGA or serial port to debug exactly what the string is that is returned by num.dec? (As an aside, in the code snippets we were using "Data5.txt", so the file "data6.txt" being empty isn't too surprising wink.gif

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
Sign In or Register to comment.