Shop OBEX P1 Docs P2 Docs Learn Events
Issue SD card with DS1307_SD-MMC_FATEngine library — Parallax Forums

Issue SD card with DS1307_SD-MMC_FATEngine library

JChrisJChris Posts: 58
edited 2015-03-05 00:10 in Propeller 1
Hello, I try to use the DS1307_SD-MMC_FATEngine library for SD card by I don't understand why it doesn't work.
No file created.
If anyone has a hint, I would appreciate

My program is:
{
 ************************************************************************************************************
 *                                                                                                          *
 *  AUTO-RECOVER NOTICE: This file was automatically recovered from an earlier Propeller Tool session.      *
 *                                                                                                          *
 *  ORIGINAL FOLDER:     Z:\...\2. SPIN Language\Programmes a modifier - espace travail\                    *
 *  TIME AUTO-SAVED:     41 minutes ago (02/07/2014 20:53:18)                                               *
 *                                                                                                          *
 *  OPTIONS:             1)  RESTORE THIS FILE by deleting these comments and selecting File -> Save.       *
 *                           The existing file in the original folder will be replaced by this one.         *
 *                                                                                                          *
 *                           -- OR --                                                                       *
 *                                                                                                          *
 *                       2)  IGNORE THIS FILE by closing it without saving.                                 *
 *                           This file will be discarded and the original will be left intact.              *
 *                                                                                                          *
 ************************************************************************************************************
.}
{
 ************************************************************************************************************
 *                                                                                                          *
 *  AUTO-RECOVER NOTICE: This file was automatically recovered from an earlier Propeller Tool session.      *
 *                                                                                                          *
 *  ORIGINAL FOLDER:     Z:\...\2. SPIN Language\Programmes a modifier - espace travail\                    *
 *  TIME AUTO-SAVED:     6 minutes ago (01/07/2014 23:45:55)                                                *
 *                                                                                                          *
 *  OPTIONS:             1)  RESTORE THIS FILE by deleting these comments and selecting File -> Save.       *
 *                           The existing file in the original folder will be replaced by this one.         *
 *                                                                                                          *
 *                           -- OR --                                                                       *
 *                                                                                                          *
 *                       2)  IGNORE THIS FILE by closing it without saving.                                 *
 *                           This file will be discarded and the original will be left intact.              *
 *                                                                                                          *
 ************************************************************************************************************
.}
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


  DO = 7
  CLK = 5
  DI = 2
  CS = 1
  WP = -1
  CD = -1
  RTCIO = -1
  RTCSCLK = -1
  RTCCE = -1
  

Var            
  Byte coucou[50]
  long OK
  
OBJ

  pst: "Parallax Serial Terminal"
  SD : "DS1307_SD-MMC_FATEngine"

Pub Main


  microSD

PUB microSD

  pst.Start(115200)

  coucou[0] := "d"
  coucou[1] := "a"
  coucou[2] := "m"
  coucou[3] := "i"
  coucou[4] := "e"
  coucou[5] := "n"
  coucou[6] := 0
  
  OK := \SD.FATEngineStart(DO, CLK, DI, CS, WP, CD, RTCIO, RTCSCLK, RTCCE)

  if OK == true
    pst.Str(String("driver launched"))
  else
    pst.Str(String("error"))

  \SD.mountPartition(0)
  

  \SD.newFile(String("coucou.txt"))
  
  \SD.openFile(String("coucou.txt"), "w")

  \SD.writeData(@coucou, 8)

  \SD.readData(@coucou, 8)

  \SD.closeFile

  pst.Str(String(pst#NL,"data written"))


Comments

  • idbruceidbruce Posts: 6,197
    edited 2015-02-28 18:02
    JChris

    In the OBJ section....

    Change

    SD :"DS1307_SD-MMC_FATEngine"


    To

    SD:"SD-MMC_FATEngine"

    EDIT: Additioally, remove the backslashes from the following lines
      OK := \SD.FATEngineStart(DO, CLK, DI, CS, WP, CD, RTCIO, RTCSCLK, RTCCE)
    
      if OK == true
        pst.Str(String("driver launched"))
      else
        pst.Str(String("error"))
    
      \SD.mountPartition(0)
      
    
      \SD.newFile(String("coucou.txt"))
      
      \SD.openFile(String("coucou.txt"), "w")
    
      \SD.writeData(@coucou, 8)
    
      \SD.readData(@coucou, 8)
    
      \SD.closeFile
    
    
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-02-28 19:12
    In general, it's a good idea to attach your program as an archive so we don't have to track down the child objects.

    I'm inclined to agree with Bruce about using the SD driver only and not use the one with the RTC if the clock isn't being used. I don't recall if using -1 for the I2C pins is enough to eliminate the issues caused by not having a RTC.

    I'm not sure why Bruce added the following:
    idbruce wrote: »
    EDIT: Additioally, remove the backslashes from the following lines

    Is there a reason you think the abort traps should be removed. IIRC, many of Kye's objects require the abort traps to work properly.

    @Chris, Have you tried a simple SD demo?

    Kye's SD driver is very picky about the way the SD card is formatted. I've had to reformat several SD cards (the slow way) before I could get them to work with Kye's driver.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-02-28 19:30
    Here's a link to a simple demo I made for the uSD card on the PropBOE. IIRC, it's a relatively simple demo. I'd think it would work with your setup if you just change the pin numbers.

    I had previously used a uSD card to record the path taken by my PropBOE-Bot. After recording the path, the robot would repeat the path it had previous taken. I thought it was kind of cool.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-28 19:30
    @Duane

    To be perfectly honest, I was not thinking clearly. Just woke up :)
    I'm inclined to agree with Bruce about using the SD driver only and not use the one with the RTC if the clock isn't being used.

    I had forgotten about RTC version :)
    Is there a reason you think the abort traps should be removed

    When I first looked at it, it just looked wrong. It has been such a long time since I have used an abort, I thought that occured because of the AUTO RECOVER :)

    EDIT: Just poor advice on my part. Sorry.
  • msrobotsmsrobots Posts: 3,709
    edited 2015-03-01 01:59
    Just ignoring the aborts does not really help you.

    @Kye did some great work to even put meaning full strings there.

    so I am not sure about your first call, but usually a value >0 represents a error string address after abort in @Kyes driver.
     OK := \SD.FATEngineStart(DO, CLK, DI, CS, WP, CD, RTCIO, RTCSCLK, RTCCE)
    
      if OK == true
        pst.Str(String("driver launched"))
      else
        pst.Str(String("error"))
    
     [B] OK:= [/B]\SD.mountPartition(0)
    [B]  if OK > 0
        pst.Str(String("the following error occurred while trying to mount: "))
        pst.Str(OK)   
      else
        pst.Str(String("mounted OK"))
    
    [/B]  \SD.newFile(String("coucou.txt"))
      
      \SD.openFile(String("coucou.txt"), "w")
    
      \SD.writeData(@coucou, 8)
    
      \SD.readData(@coucou, 8)
    
      \SD.closeFile
    .
    

    This will give you the reason while mount failed, if it failed.

    sadly this abort way collides with functions returning values. In case of an abort @Kyes driver returns the string address of the error string. Better would have been to return that address as NEGATIVE number. Easier to distinguish from NORMAL return values like number of bytes read when using readData().

    But there is some method/function in @Kyes driver to check for success of the last operation. I am usually using a heavily modified version in my projects, since I always run out of space, so I do not remember the original name in @Kyes original source. getLastError()?

    Look at his source. It is quite at the beginning of the PUBlic functions.

    Far away from any PropTool or propeller by now, so I cant look at my sources.

    Enjoy!

    Mike
  • JChrisJChris Posts: 58
    edited 2015-03-01 10:20
    @Duane, What are the specifics for formatting? Because I tried several times to reformate many SD cards but it doesn't work.

    I haven't tried simple SD demo because I don't have it

    I have an error message: Disk IO error
    How can I fix this error?
  • PublisonPublison Posts: 12,366
    edited 2015-03-01 10:55
    JChris wrote: »
    What are the specifics for formatting? Because I tried several times to reformated many SD cards but it doesn't work.

    I haven't tried simple SD demo

    I have an error message: Disk IO error
    How can I fix this error?

    Are you reformatting on a PC? Quick format does not work sometimes. What OS are you using?


    Where did you find "DS1307_SD-MMC_FATEngine"? I can't locate it anywhere, or did you just rename it?

    I'm with Duane. You need to archive the entire program with the Propeller Tool and post the zip.
  • JChrisJChris Posts: 58
    edited 2015-03-01 14:28
    Yes I reformated my SD card on a PC. I used complete formatting. I use Windows 8

    I found "DS1307_SD-MMC_FATEngine" on OBEX (http://obex.parallax.com/object/16)SD_Card.zip
  • KyeKye Posts: 2,200
    edited 2015-03-01 14:35
    Hi,

    A disk i/o error means that either the electrical connection is bad or that my driver can't read the card. It's rare to run into cards that can't be read. Check your wire connections and make sure all the pins in the code are correct. A common mistake is swapping the DI and DO pins. DO is the card's data out. Not the prop chip's data out.

    If you're 100% sure the electrical connections are correct then my driver may not be able to read the card. If this is the case then use a different card. If all your different cards can't be read then you likely still have an electrical connection issue.
  • JChrisJChris Posts: 58
    edited 2015-03-03 09:56
    Hi Kye,

    I use a propeller C3 board and I would like to know what are pins that have to be used for activate the SD card.

    I found a program but I am wondered if the _cspin and _rtcres1 are not inverted?

    And I can't create a new file on the SD card, It's why if you could help me for connection of pins, I would appreciate

    The program is the following:
    {{
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // SD Card Profiler
    //
    // Author: Kwabena W. Agyeman
    // Updated: 3/23/2011 (5/13/2011 by Michael Green)
    // Designed For: P8X32A
    // Version: 1.0 - Special
    //
    // Copyright (c) 2011 Kwabena W. Agyeman
    // See end of file for terms of use.
    //
    // Update History:
    //
    // v1.0 - Special - Original release - 3/23/2011.
    //
    // On startup the program blinks the status LED at 4 Hz signaling that it is writing basic file system data. After the program
    // finishes writing basic file system data it then begins to speed test the file system and blink the status LED at 8 Hz. Once
    // finished speed testing the file system the program then waits for reset or power down and keeps the status LED lit solid.
    // If an error occurs that the program is unable to handle it will blink the status LED at 1 Hz and wait for reset or power
    // down. Remove the SD card from the propeller chip once the program finishes as indicated by the status LED and insert the SD
    // card into a computer to see the results of the profiler. Do not remove the SD card until the propeller chip is finished
    // running the profiler program or the SD card partition may become corrupted.
    //
    // Nyamekye,
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }}
    
    CON
    
      _clkmode = xtal1 + pll16x ' The clkfreq is 80MHz.
      _xinfreq = 5_000_000 ' Demo board compatible.
    
      _cspin   =  25 ' CS count counter
      _dipin   =  9 ' SPI MISO
      _dopin   = 10 ' SPI MOSI
      _clkpin  = 11 ' SPI Clock
      _cdpin   = -1 ' -1 if unused.
      _wppin   = -1 ' -1 if unused.
    
      _rtcres1 = 8 ' CS /clear counter
      _rtcres2 =  5 ' SD card select code  
      _rtcres3 =  0 ' RTC select code (no RTC)  
    
      _statuspin = 15 ' Status LED pin number.
    
    OBJ
    
      fat0: "SD-MMC_FATEngine.spin"
      pst: "Parallax Serial Terminal"
    
    PUB main | errorString, OK, OK1, OK2
    
      pst.Start(115200)
    
      ' "fatEngineStart" is only called once. Either driver object can call it.
      OK := \fat0.fatEngineStart( _dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, {
                        } _rtcres1, _rtcres2, _rtcres3)
    
      if OK == true
        pst.Str(String("driver launched",13))
      else
        pst.Str(String("error"))
    
      \fat0.mountPartition(0)
    
      if(fat0.partitionMounted)
        OK := \fat0.unmountPartition
    
      if OK == true
        pst.Str(String("partition mounted"))
      else
        pst.Str(String("error"))
    
      errorString := \fat0.newFile(string("Profile.txt"))
    
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-03 10:58
    The C3 uses an IC counter to set the chip select pins of the various SPI devices (including the SD card). You need to access this IC in your program and pulse the pin the appropriate number of times to select the SD card. I've only used pre-written SPI drivers on the C3. I suggest starting with an example program to see how it's done and modify it to suit your needs.
  • KyeKye Posts: 2,200
    edited 2015-03-03 16:28
    That board is not compatible with my code. However, others have remixed my code and made it work on the C3. Search through the forum for a changed version.
  • JChrisJChris Posts: 58
    edited 2015-03-04 15:24
    @Kye
    Do you mean that your library would work with other propeller boards but not with the C3?
    What's the difference. is it due to the way the SPI bus is implemented on the C3 board?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 15:29
    JChris wrote: »
    What's the difference. is it due to the way the SPI bus is implemented on the C3 board?

    I'm sure this is the reason.

    It shouldn't be too hard to modify Kye's driver to use with the C3 and there might already be a C3 friendly version available somewhere.
  • JChrisJChris Posts: 58
    edited 2015-03-04 16:03
    OK. Any hint where I should look to adapt it for the C3 board? I already added a few lines to increment the IC counter to make sure the right SPI channel was selected (5 on the C3).
  • KyeKye Posts: 2,200
    edited 2015-03-04 18:31
    That's an older version. But, it's more or less the same.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-04 18:51
    I haven't checked the circuit of the C3.

    Haveyou tried Kye's non-RTC version first? If not, try that first.

    Otherwise, if you look at the code in my PropOS (see link in m signature) and change the xtal freq (5 or 10MHz) and the PLL*16 or *8, and change the SD pins in the _hwdef.spin file, my PropOS should work using the Prop Serial Terminal connected to P30/31 (propplug to USB). You will need to recompile and then copy all the *.cmd files to the SD root directory.
    If you want to tell me the xtal and sd pinouts I can compile for you and post all the files you require in the SD root directory.

    I use a modified variant of Kye's FAT Engine to allow for shared SPI pins that I use on my RamBlades.
    If this works, then you have proved the hardware, so its a matter of checking the SD pins to see if they are shared on the C3.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 19:49
    Cluso99 wrote: »
    I haven't checked the circuit of the C3.

    . . .

    If this works, then you have proved the hardware, so its a matter of checking the SD pins to see if they are shared on the C3.

    In order to save I/O pins on the C3, the chip select lines of the SPI devices are controlled with a multiplexing chip.

    In general none of the normal SPI objects work on the C3 without being modified.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 20:38
    The demo code Mike posted in the other thread didn't compile initially. I fixed a couple of typos and changed it to use the Parallax Serial Terminal. I also added my demo program to Mike's program.

    I just tested this on my C3 and it appears to work.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-05 00:10
    Duane,
    I share SPI pins on my RamBlades so I had to modify all the SD drivers to ensure the SD card released the DO pin. This involved sending some more CLKs.

    I just checked my version of Kye's FAT Engine - I did not have to do this modification to Kye's driver (which IIRC was his V2).

    BTW CLKFREQ is at hub $0000 and CLKMODE is at hub $0004, so my recollection above was incorrect.
Sign In or Register to comment.