Shop OBEX P1 Docs P2 Docs Learn Events
SPin2 SD card directory display — Parallax Forums

SPin2 SD card directory display

Has anyone got a very simple SPin2 app or obj to read an SPi connected SD card and display on the terminal.

To show that it is working and reading files, a bit of a SD Card "hello world"

Thanks

Comments

  • AndyPropAndyProp Posts: 55
    edited 2024-01-23 09:32

    Read from SD Card and display some contents of a file

    CON 
      _clkfreq  = 300_000_000
    
    CON
      HEAPSIZE = 32768
    
    VAR
      long f1
      byte bstr[512]
    
    OBJ
       c : "libc.a"               ' C standard library
    
    PUB main() : err | i,ch
      err := _mount(@"/sd", c._vfs_open_sdcard())
      debug(sdec(err))
      ifnot err
        f1 := c.fopen(@"/sd/test.txt",@"rb")
        debug(sdec(f1))
        ifnot f1
          debug("Error at open")
        else
          c.fread(@bstr, 511, 1, f1)
          debug(zstr(@bstr))
        c.fclose(f1)
    
    
  • Just posted this FAT32 object to the OBEX. Tried to make it as simple to use as possible.

    CON
      _CLKFREQ = 80_000_000
      _SD_MISO = 58                   
      _SD_SCK  = 61                   
      _SD_MOSI = 59                   
      _SD_CS   = 60                   
    VAR
      byte  buffer[2048]
    OBJ
      sd : "SD card driver"
    PUB main() 
      if sd.mount(_SD_CS, _SD_MOSI, _SD_MISO, _SD_SCK)
        sd.openFile(string("filename.txt"))
        sd.read(@buffer,sd.fileSize())
        debug(zstr(@buffer))
    
  • @ChrisGadd said:
    Just posted this FAT32 object to the OBEX. Tried to make it as simple to use as possible.

    CON
      _CLKFREQ = 80_000_000
      _SD_MISO = 58                   
      _SD_SCK  = 61                   
      _SD_MOSI = 59                   
      _SD_CS   = 60                   
    VAR
      byte  buffer[2048]
    OBJ
      sd : "SD card driver"
    PUB main() 
      if sd.mount(_SD_CS, _SD_MOSI, _SD_MISO, _SD_SCK)
        sd.openFile(string("filename.txt"))
        sd.read(@buffer,sd.fileSize())
        debug(zstr(@buffer))
    

    I tried it, did not work on my card, I am having a hard time with cards at the moment anyway so it does not surprise me.

    I can list the directory in Taqoz via Flexprop terminal and see a text file exists but that's about it.

    Attached an image of mine in case you like to test that type too.

  • Re-verified that it works with all of my cards, all but the 512MB are SDHC, in a full-size socket and on the P2 eval board micro socket, all good provided it's formatted as FAT32.
    The mounting/initialization routines are based on FSRW, and the spi routines on sdspi_fast_bashed.

  • @ChrisGadd said:
    Re-verified that it works with all of my cards, all but the 512MB are SDHC, in a full-size socket and on the P2 eval board micro socket, all good provided it's formatted as FAT32.
    The mounting/initialization routines are based on FSRW, and the spi routines on sdspi_fast_bashed.

    Thanks Chris, I will have a look in a few days when I get some new boards.

    It would be interesting if somehow you could make a version in Forth & Taqoz or working together so that Taqoz has the 32 bit ability

Sign In or Register to comment.