Shop OBEX P1 Docs P2 Docs Learn Events
Problem Interfacing micro SD card with Propeller — Parallax Forums

Problem Interfacing micro SD card with Propeller

big_red_eightbig_red_eight Posts: 2
edited 2012-01-05 06:34 in Propeller 1
Hey everybody,
I am trying to interface with multiple modules: GPS, LCD, XBee, and micro SD. I have successfully communicated with all of the components, but the SD card refuses to reliably write files. I can write a program that writes successfully to the card, but a seemingly benign change will cause written files to be corrupted (the titles of the files are non-ascii characters and the computer can't open them). I constructed a rudimentary program that reproduces the problem.

As posted, the following code wrote all three files successfully. However, if I un-commented the GPU.start_GPS line, the third file is corrupted. The intermittent delays is me trying to reproduce this behavior. I have checked my wiring, and I am pretty sure it is correct. Again, I have successfully interfaced with all modules, so I don't think it is hardware. Also, I am using version 2.6 of the "fsrw.spin" file.
Could it be the way I formatted the SD card? Any help would be greatly appreciated.

micro SD card INFO:
16GB
formatted using Windows VISTA (FAT32, allocation size = 16kb)

con
  _xinfreq      = 5_000_000  
  _clkmode      = xtal1 + pll16x
  LCD_pin = 27
  SD_pin = 0

  Prop2GPS_Rx = 24
  Prop2GPS_Tx = 25
Var
  byte message1[20]
  byte message2[20]
  byte sdready
  byte filename[20]


OBJ
 lcd           :       "Serial_Lcd"
 delay         :       "Timing"
 sdfat         :       "fsrw"
 GPU           :       "gps_utils"

PUB main
         'GPU.start_GPS(Prop2GPS_Rx, Prop2GPS_Tx, 0, 4800)
         lcd.start(LCD_pin, 19200, 4)
         lcd.cls

         delay.pause1ms(100)  

         
         message1 := string("please work")
         message2 := string("another message")
        ' mount SD card
        sdready := sdfat.mount(SD_pin)
        lcd.str(message1)
        '' write first file
        filename := string("file_a6.txt")
        sdfat.popen(filename, "w")
        sdfat.pwrite(message1,10)
        delay.pause1ms(10)   
        sdfat.pwrite(message2,10)
        sdfat.pputc(65)
        sdfat.pclose
 
       
        filename := string("file_b6.txt")  
        sdfat.popen(filename, "w")
        sdfat.pwrite(message2,10)
        sdfat.pclose
 
        delay.pause1ms(1000)  
        filename := string("file_c6.txt")  
        sdfat.popen(filename, "w") 
        sdfat.pwrite(message2,10)
        sdfat.pclose        

        delay.pause1ms(1000)

The start_GPS method is posted below:
PUB start_GPS (PropRx_pin, PropTx_pin, mode, baud)
    cog_used := uart.start(PropRx_pin, PropTx_pin, mode, baud)

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2012-01-04 14:25
    You are using message1, message2 and filename as pointers but you declared them as byte arrays. When you say "filename := string("file_a6.txt")" you are storing the 16-bit address of the string "file_a6.txt" in the first location of the byte array filename. In Spin, filename is the same as filename[0]. Since this is a byte variable it is only saving the 8 LSBs of the string address. When you call popen you are passing a pointer to a location in the first 512 bytes of hub RAM.

    Your test program will work if you declare message1, message2 and filename as word or long variables.
  • big_red_eightbig_red_eight Posts: 2
    edited 2012-01-05 06:34
    Great, it works. Thanks a lot. So, I guess the times in which my program did successfully write to the card was when the address of the string was in the first 512 bytes of memory. I probably should have read more into what the "string" method does! I assumed it was dumping ascii characters into each array unit. Anyway, thanks a lot.
Sign In or Register to comment.