MMC/SD card initialization


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Apr 2016
    Posts
    7

    Default MMC/SD card initialization

    Hi all,

    I am trying to communicate to a SD/MMC card. I have search all over the internet to find examples to get it to work, but it doesn't.
    I have made my own PCB according to the schematic that micro engineering has provided. I have also already checked if the SPI is
    active, and it is. But right after i call FSinit, i get an error (i read out the error according the example of micro engineering). The
    output is as follows:
    FAT_error = 6
    SDC_status = 1
    SDC_response = 255

    This is de code for generating to general variables for the SD include:
    Code:
     SD_WE       var PORTC.6     'SD card Write Protect 
        SD_WE_TRIS  var TRISC.6     'SD card Write Protect direction
        SDI         var PORTC.4     'SPI data in
        SDI_TRIS    var TRISC.4     'SPI data in direction
        SCL         var PORTC.3     'SPI clock
        SCL_TRIS    var TRISC.3     'SPI clock direction
        SD_CS       var PORTA.5     'SD card Chip Select
        SD_CS_TRIS  var TRISA.5     'SD card chip select direction
        SD_CD       var PORTC.7     'SD card Detect
        SD_CD_TRIS  var TRISC.7     'SD card detect direction
        SDO         var PORTC.5     'SPI data out
        SDO_TRIS    Var TRISC.5     'SPI data out direction
    and my own code in main:
    Code:
        gosub FSInit                'initialise the SD card
        Serout2 PORTB.1, 84, ["Init: ", FAT_error, " ", SDC_status, " ", SDC_response, $d, $a]
        gosub SD_error_check        'Check for errors on SD card
        gosub FINDfirst             'Look for files on SD card
        While(FAT_error = 0)        'Find next file on card
            files_found = files_found + 1
            Gosub FINDnext           
        Wend
    Can someone give me a direction to search for. I have already wasted lots of time to confirm if
    it is actually working (PIC) and I am know at the point of desperation (almost ).

    I'm waiting for that good old little segment that you always forget somehow ;(.

    kind regards,

    Remco

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,983


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Code:
    ' This section defines a specific short (8.3) filename
    '  Note that spaces are use in empty elements and must be upper case for Windows
    	FAT_FileName[0] = "T"
    	FAT_FileName[1] = "E"
    	FAT_FileName[2] = "S"
    	FAT_FileName[3] = "T"
    	FAT_FileName[4] = "1"
    	FAT_FileName[5] = " "
    	FAT_FileName[6] = " "
    	FAT_FileName[7] = " "
    	FAT_FileName[8] = "T"
    	FAT_FileName[9] = "X"
    	FAT_FileName[10] = "T"
    This is important.

    Robert
    Last edited by Demon; - 17th April 2016 at 13:57.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,983


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Kept on going through the pages of threads and found this one:
    http://www.picbasic.co.uk/forum/show...hlight=sd+card

    They point to MeLabs samples (that we probably already have in PBP):
    http://melabs.com/samples/PBP-mixed/index.htm

    (scroll down to sdfs3.pbp)

    It's the same ReadMe, but it has an earlier date on at least two of the files at a quick glance.

    I'd use that one. It has the truckload of pins like you are using, so it's possible it'll suit your needs.

    Nice schematic too.

    Robert


    EDIT: And after going through the files a bit, this is where I notice that this is exactly where you got your code from.
    Last edited by Demon; - 17th April 2016 at 13:15.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,983


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Did you notice this part?

    The included PICBASIC PRO code requires PBP version 2.50 or later. It uses
    the PIC18 long libraries that are part of that version of the compiler. This
    also means the files only work on PIC18 parts. Be sure to specify the long
    version of the compiler, PBPL
    , when compiling programs using these files.
    Last edited by Demon; - 16th April 2016 at 01:55.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,983


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Did you go through the little test program?

    Code:
    ' Name        : sdfs3.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6 (PBPL only)
    ' Assembler   : MPASM
    ' Target PIC  : PIC16F4550
    ' Hardware    : Schematic available in http://melabs.com/resources/samples/pbp/sdfs3.zip
    ' Oscillator  : 20MHz
    ' Keywords    : SD Card, SD/MMC, FAT16
    ' Description : 10/02/08 - PICBASIC PRO 2.50L test program to talk to FAT16 
    ' formatted MMC/SD cards with PIC18F4550.  This is only a test program that 
    ' is part of a larger project.  The complete fileset with schematic, includes, 
    ' and details can be found at download: 
    ' http://melabs.com/resources/samples/pbp/sdfs3.zip
    
    
    	Define	OSC	20	' 20 MHz oscillator
    
    ' Alias PIC pins and registers for SD/MMC card
    SD_WE		Var	PORTA.4	' SD card write protect
    SD_WE_TRIS	Var	TRISA.4	' SD card write protect direction
    SDI		Var	PORTB.0	' SPI data in
    SDI_TRIS	Var	TRISB.0	' SPI data in direction
    SCL		Var	PORTB.1	' SPI clock
    SCL_TRIS	Var	TRISB.1	' SPI clock direction
    SD_CS		Var	PORTB.3	' SD card chip select
    SD_CS_TRIS	Var	TRISB.3	' SD card chip select direction
    SD_CD		Var	PORTB.4	' SD card detect
    SD_CD_TRIS	Var	TRISB.4	' SD card detect direction
    SDO		Var	PORTC.7	' SPI data out
    SDO_TRIS	Var	TRISC.7	' SPI data out direction
    
    
    ' Include the SD/MMC subroutines (found in http://melabs.com/resources/samples/pbp/sdfs3.zip)
    	Include "SDFS.PBP"
    	SDC_UseHardSPI = TRUE	' Use hardware SSP port for SPI.
    
    	ADCON1 = 15		' All I/O pins digital
    	Pause 100
    
    	' FSInit initializes the card and reads all the preliminary information from it
    	Gosub FSInit
    	Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
    	If (FAT_error != 0) Then Stop
    
    	' Display card directory
    	Gosub FINDfirst		' Find first file on card
    	While (FAT_error = 0)
    		Serout2 PORTC.6, 84, [Str FAT_FileName\11, $d, $a]
    		Gosub FINDnext	' Find next file on card
    	Wend
    
    ' This section defines a specific short (8.3) filename
    '  Note that spaces are use in empty elements and must be upper case for Windows
    	FAT_FileName[0] = "T"
    	FAT_FileName[1] = "E"
    	FAT_FileName[2] = "S"
    	FAT_FileName[3] = "T"
    	FAT_FileName[4] = "1"
    	FAT_FileName[5] = " "
    	FAT_FileName[6] = " "
    	FAT_FileName[7] = " "
    	FAT_FileName[8] = "T"
    	FAT_FileName[9] = "X"
    	FAT_FileName[10] = "T"
    
    ' Set file time to 8:30:10 and date to 1/1/2008
    	FAT_seconds = 5
    	FAT_minutes = 30
    	FAT_hours = 8
    	FAT_day = 1
    	FAT_month = 1
    	FAT_year = 28
    
    ' Open a file for write
    	FAT_mode = "w"		' Write mode
    	Gosub FSfopen		' Open file pointed to by Byte array FAT_FileName
    	Serout2 PORTC.6, 84, ["Open for write: ", Dec FAT_error, $d, $a]
    	If (FAT_error != 0) Then Stop
    
    ' Write to file
    	FAT_src[0] = "A"
    	FAT_src[1] = "B"
    	FAT_src[2] = "C"
    	FAT_count = 3
    	Gosub FSfwrite
    	Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
    	If (FAT_error != 0) Then Stop
    
    ' Close file
    	Gosub FSfclose
    	Serout2 PORTC.6, 84, [ "Close ", Dec FAT_error, $d, $a]
    	If (FAT_error != 0) Then Stop
    
    ' Open a file for read
    	FAT_mode = "r"		' Read mode
    	Gosub FSfopen		' Open file pointed to by Byte array FAT_FileName
    	Serout2 PORTC.6, 84, ["Open: ", Dec FAT_error, $d, $a]
    	If (FAT_error != 0) Then Stop
    
    ' Read and display the whole file
    	FAT_count = 1		' Read 1 byte to buffer at a time
    	Gosub FSfread
    	While (FAT_error = 0)
    		Serout2 PORTC.6, 84, [FAT_dest[0]]
    		FAT_count = 1	' Read 1 byte to buffer at a time
    		Gosub FSfread
    	Wend
    	Serout2 PORTC.6, 84, [ "Read: ", Dec FAT_error, $d, $a]
    
    ' Delete a file
    '	Gosub FSremove		' Delete file pointed to by Byte array FAT_FileName
    '	Serout2 PORTC.6, 84, ["Remove: ", Dec FAT_error, $d, $a]
    '	If (FAT_error != 0) Then Stop
    
    ' Rename a file
    ' FAT_FileName2 is new name
    '	FAT_FileName2[0] = "T"
    '	FAT_FileName2[1] = "E"
    '	FAT_FileName2[2] = "S"
    '	FAT_FileName2[3] = "T"
    '	FAT_FileName2[4] = "2"
    '	FAT_FileName2[5] = " "
    '	FAT_FileName2[6] = " "
    '	FAT_FileName2[7] = " "
    '	FAT_FileName2[8] = "T"
    '	FAT_FileName2[9] = "X"
    '	FAT_FileName2[10] = "T"
    '	Gosub FSrename		' Rename file pointed to by Byte array FAT_FileName
    '	Serout2 PORTC.6, 84, ["Rename: ", Dec FAT_error, $d, $a]
    '	If (FAT_error != 0) Then Stop
    
    	End
    And now I notice you copied from this program, yeeesh, I'm great help tonight.

    Dumb question, have you tried using the sample test program AS IS? (correcting pins and CONFIGs of course)

    Robert


    EDIT: The Target PIC must be a typo in the comments:
    Code:
    ' Target PIC  : PIC16F4550
    The Description is most likely correct:
    Code:
    ' Target PIC  : PIC18F4550
    Last edited by Demon; - 17th April 2016 at 13:20. Reason: Highlighting points of interest
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Post your whole code. State the parts you are using and how they are connected. Verify the SD card is good, 2 gb or less and formatted FAT16.

    Do you have this line near the top of your code ?
    Code:
     SDC_UseHardSPI = FALSE    ' Use hardware SSP port for SPI.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,983


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Code:
    CE_GOOD        Con    0    ' No error
    CE_ERASE_FAIL    Con    1    ' An erase failed
    CE_NOT_PRESENT    Con    2    ' No device was present
    CE_NOT_FORMATTED Con    3    ' The disk is of an unsupported format
    CE_BAD_PARTITION Con    4    ' The boot record is bad
    CE_UNSUPPORTED_FS Con    5    ' The file system type is unsupported
    CE_INIT_ERROR    Con    6    ' An initialization error has occured
    CE_NOT_INIT    Con    7    ' An operation was performed on an uninitialized device
    CE_BAD_SECTOR_READ Con    8    ' A bad read of a sector occured
    CE_WRITE_ERROR    Con    9    ' Could not write to a sector
    CE_INVALID_CLUSTER Con    10    ' Invalid cluster value > maxcls
    CE_FILE_NOT_FOUND Con    11    ' Could not find the file on the device
    CE_DIR_NOT_FOUND Con    12    ' Could not find the directory
    CE_BAD_FILE    Con    13    ' File is corrupted
    CE_DONE        Con    14    ' No more files in this directory
    CE_COULD_NOT_GET_CLUSTER Con 15    ' Could not load/allocate next cluster in file
    CE_FILENAME_2_LONG Con    16    ' A specified file name is too long to use
    CE_FILENAME_EXISTS Con    17    ' A specified filename already exists on the device
    CE_INVALID_FILENAME Con    18    ' Invalid file name
    CE_DELETE_DIR    Con    19    ' The user tried to delete a directory with FSremove
    CE_DIR_FULL    Con    20    ' All root dir entry are taken
    CE_DISK_FULL    Con    21    ' All clusters in partition are taken
    CE_DIR_NOT_EMPTY Con    22    ' This directory is not empty yet, remove files b4 deleting
    CE_NONSUPPORTED_SIZE Con 23    ' The disk is too big to format as FAT16
    CE_WRITE_PROTECTED Con    24    ' Card is write protected
    CE_FILENOTOPENED Con    25    ' File not opened for the write
    CE_SEEK_ERROR    Con    26    ' File location could not be changed successfully
    CE_BADCACHEREAD    Con    27    ' Bad cache read
    CE_CARDFAT32    Con    28    ' FAT32 - card not supported
    CE_READONLY    Con    29    ' The file is read-only
    CE_CARDFAT12    Con    30    ' FAT12 - card not supported
    CE_WRITEONLY    Con    31    ' The file is write-only
    CE_INVALID_ARGUMENT Con    32    ' Invalid argument
    CE_FAT_EOF    Con    60    ' Attempt to read beyond the FAT's EOF
    CE_EOF        Con    61    ' End of file reached
    Code:
    sdcValid	Con	0
    sdcCardInitCommFailure Con 1
    sdcCardNotInitFailure Con 2
    sdcCardInitTimeout Con	3
    'sdcCardTypeInvalid Con	4
    sdcCardBadCmd	Con	5
    sdcCardTimeout	Con	6
    'sdcCardCRCError	Con	7
    sdcCardDataRejected Con	8
    'sdcEraseTimedOut Con	9
    Code:
    SDC_FLOATING_BUS Con	$ff
    SDC_BAD_RESPONSE Con	SDC_FLOATING_BUS
    Well, the codes aren't much help.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    Apr 2016
    Posts
    7


    Did you find this post helpful? Yes | No

    Post Re: MMC/SD card initialization

    First of all thank you for all you replies.

    With regard to you Demon:
    *Yes, I use capital letters for the files.
    *Yes, I have selected to use PBPL (get the message when it is compiled).
    *Yes, I am using an PIC18 part (specific PIC18F26K80).
    *And yes, I also found what the error codes represents and as you stated they aren't so much of a help.

    With regards to mackrackit:
    As you can see in the code below, i have specified your line directly after I include the SDFS file.
    And i use a 2GB card and it is in FAT format (and that will be FAT16, according to Microsoft).

    I have already established that all my IO works, but today I am gonna try to monitor the data that is send
    to the SD card and what he will send back

    Code:
    'configuration bits   
    #CONFIG
        CONFIG  RETEN = ON          ; Ultra low-power regulator is Enabled (Controlled by SRETEN bit)
        CONFIG  INTOSCSEL = HIGH    ; LF-INTOSC in High-power mode during Sleep
        CONFIG  SOSCSEL = HIGH      ; High Power SOSC circuit selected
        CONFIG  XINST = OFF         ; Disabled
        CONFIG  FOSC = INTIO2       ; Internal RC oscillator
        CONFIG  PLLCFG = ON         ; Enabled
        CONFIG  FCMEN = ON          ; Enabled
        CONFIG  IESO = OFF          ; Disabled
        CONFIG  PWRTEN = ON         ; Enabled
        CONFIG  BOREN = SBORDIS     ; Enabled in hardware, SBOREN disabled
        CONFIG  BORV = 3            ; 1.8V
        CONFIG  BORPWR = ZPBORMV    ; ZPBORMV instead of BORMV is selected
        CONFIG  WDTEN = ON          ; WDT controlled by SWDTEN bit setting
        CONFIG  WDTPS = 512         ; 1:512
        ;CONFIG  CANMX = PORTB      ; ECAN TX and RX pins are located on RB2 and RB3, respectively
        ;CONFIG  MSSPMSK = MSK7     ; 7 Bit address masking mode
        CONFIG  MCLRE = ON          ; MCLR Enabled, RE3 Disabled
        CONFIG  STVREN = ON         ; Enabled
        CONFIG  BBSIZ = BB2K        ; 2K word Boot Block size
        CONFIG  CP0 = OFF           ; Disabled
        CONFIG  CP1 = OFF           ; Disabled
        CONFIG  CP2 = OFF           ; Disabled
        CONFIG  CP3 = OFF           ; Disabled
        CONFIG  CPB = OFF           ; Disabled
        CONFIG  CPD = OFF           ; Disabled
        CONFIG  WRT0 = OFF          ; Disabled
        CONFIG  WRT1 = OFF          ; Disabled
        CONFIG  WRT2 = OFF          ; Disabled
        CONFIG  WRT3 = OFF          ; Disabled
        CONFIG  WRTC = OFF          ; Disabled
        CONFIG  WRTB = OFF          ; Disabled
        CONFIG  WRTD = OFF          ; Disabled
        CONFIG  EBTR0 = OFF         ; Disabled
        CONFIG  EBTR1 = OFF         ; Disabled
        CONFIG  EBTR2 = OFF         ; Disabled
        CONFIG  EBTR3 = OFF         ; Disabled
        CONFIG  EBTRB = OFF         ; Disabled
    #ENDCONFIG
    
    'alias PIC pins definition 
        OP1         var PORTC.1     'For JUMPER1
        OP1_TRIS    var TRISC.1
        TX1         var PORTC.0
        TX1_TRIS    var TRISC.2
        OP2         var PORTB.4
        OP2_TRIS    var TRISB.4
        RX1         var PORTC.2
        RX1_TRIS    var TRISC.2
        
        OP3         var PORTB.2     'For JUMPER2
        OP3_TRIS    var TRISB.2
        TX2         var PORTB.3
        TX2_TRIS    var TRISB.3
        OP4         var PORTB.0
        OP4_TRIS    var TRISB.0
        RX2         var PORTB.1
        RX2_TRIS    var TRISB.1
        
        OP5         var PORTA.3     'For JUMPER3
        OP5_TRIS    var TRISA.3
        TX3         var PORTA.2
        TX3_TRIS    var TRISA.2
        OP6         var PORTA.6
        OP6_TRIS    var TRISA.6
        RX3         var PORTA.7
        RX3_TRIS    var TRISA.7
        
        SHTDWN      var PORTA.1     'Shutdown 3.3V regulator
        SHTDWN_TRIS VAR TRISA.1 
        
        SD_WE       var PORTC.6     'SD card Write Protect 
        SD_WE_TRIS  var TRISC.6     'SD card Write Protect direction
        SDI         var PORTC.4     'SPI data in
        SDI_TRIS    var TRISC.4     'SPI data in direction
        SCL         var PORTC.3     'SPI clock
        SCL_TRIS    var TRISC.3     'SPI clock direction
        SD_CS       var PORTA.5     'SD card Chip Select
        SD_CS_TRIS  var TRISA.5     'SD card chip select direction
        SD_CD       var PORTC.7     'SD card Detect
        SD_CD_TRIS  var TRISC.7     'SD card detect direction
        SDO         var PORTC.5     'SPI data out
        SDO_TRIS    Var TRISC.5     'SPI data out direction
            
        Rail_v      var PORTA.0     'incomming 5V rail
        Rail_v_TRis var TRISA.0
        
        LED         var PORTB.5     'Status LED
        LED_TRIS    var TRISB.5    
    
        MCLR        var PORTE.3     'MCLR 
        
        PGD         var PORTB.7     'PGD programming data
        PGD_TRIS    var TRISB.7
        PGC         var PORTB.6     'PGC programming clock
        PGC_TRIS    var TRISB.6
    
    'includes:
        include "SDFS.bas"          ' include for using FAT16-SD card
        'include "SDFShc32d.pbp."
        SDC_UseHardSPI = FALSE 
        INCLUDE "DT_INTS-14.bas"    ' Base Interrupt System
        INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
        include "modedefs.bas"
        
    'defines for compiler
        DEFINE  LOADER_USED 0       'Not using a bootloader 
        define  OSC 16              'Tell PBP to expect 64MHz clock    
            
    'watchdog settings
        WDTCON = 22                 'Set WDT to 2 s (default = 2 s)
        WDTCON.0 = 1                'enable watchdog
        
    'oscillator settings
        OSCCON = %01110000          'Set internal clock to 16 MHz  
        'OSCTUNE = %11000000         'enable PLL (clock = now 64 MHz)
        
    'interrupt settings
        INTCON = %00000000          'disabled all interupts 
        
    'option settings
    
    'analog i/o port settings     
        ANCON0 = %00000001
        ANCON1 = %00000000 
        SLRCON = %00000000
            
    'digital i/o port settings 
        PADCFG1 = %00000000         'disable pull-up  
        WPUB = %00000000            'disable pull-up  
        ODCON = %00000000           'disable open-drain  
        TRISA = %00010101           'Port A
        TRISB = %11001000           'Port B      
        TRISC = %11010001           'Port C
        
    'adc settings
        ADCON0 = %00000001
        ADCON1 = %00110000          'Use internal 4.1 refference
        ADCON2 = %10000000          'Right justified
         
    'uart settings
    
               
    'spi settings
           
    'timer2
        T2CON = %01111111           'postscaler=16,timer on, prescaler=16 (62500 Hz)     
        PR2 = 251                   'comperator value is set to divide by 251(250 Hz)
        PIR2.1 = 0                  'reset flag
             
    'constant definition
        FIRMWARE_VERSION_M  con 00  ' M + . + S is the firmware version -> XX.XX
        FIRMWARE_VERSION_S  con 10
        
        log_control_max     con 53  'Maxmimum data to be received from control board
        log_pumpfix_max     con 11  'and pumpfix board after logging reqeust
        log_row_bytes       con 67  'Add log_control and log_pumpfix + carriage return and 2 tabs
        Startup_control_max con 1   'Maximu data to be received from control after start up request
        log_general_max     con 207 'Maximum of data that is contained in the general information block 
        log_info_banner     con 229 'maximum of data that is contained in the infromation banner for the logging
        log_ofset_bytes     con 436 'Ofset in bytes for log data to be stored : log_general_max + log_info_banner
        MAX_NOEN            con 8000'max of log entries, after that a new file has to be created (~500 MB)
        MAX_files           con 3
    
        File_PN_L           con 10  'Following numbers represents the maximum number 
        File_SN_L           con 9   'of bytes (LENGTH) that can be written to the 
        File_FV_L           con 5   'file for each point in the general information 
        File_TSO_L          con 6   'banner.
        File_TSON_L         con 6   'One byte represents one decimal value in a .txt
        File_TT_L           con 10  'file.
        File_NOER_L         con 9
        File_NOEN_L         con 4
        
        File_PN_S           con 15  'Following numbers represents the first (START)  
        File_SN_S           con 43  'possistion (byte) of the corresponding general  
        File_FV_S           con 72  'information. 
        File_TSO_S          con 98  'All the given numbers are measured from the 
        File_TSON_S         con 116 'starting point (0) in the file.
        File_TT_S           con 137
        File_NOER_S         con 167
        File_NOEN_S         con 197 
            
    'variable definition
        TimerTick_max       var word'variable to contain needed interval
        TimerTick_counter   var word'variable that counts the interval
        LED_blink_counter   var byte'variable for pulses on the error LED
        i                   var byte
        
        log_control_data    var byte [log_control_max]      'array for received data
        log_pumpfix_data    var byte [log_pumpfix_max]      'array for received data
        strtup_control_data var byte [Startup_control_max]  'array for recived data 
        AN0_value           var word'variable to store ADC value of 5V rail     
    
        files_found         var word'For indexing the number of files
        
        File_PN             var byte[File_PN_L]     'Variables to write to the 
        File_SN             var byte[File_SN_L]     'SD card when there needs to
        File_FV             var byte[File_FV_L]     'be a new file to be 
        File_TSO            var byte[File_TSO_L]    'generated
        File_TSON           var byte[File_TSON_L]
        File_TT             var byte[File_TT_L]
        File_NOER           var byte[File_NOER_L]
        File_NOEN           var byte[File_NOEN_L]
        
        Current_TSO         var long'Current values that are read out from the file 
        Current_TSON        var long'on the SD card. These wil also be used for 
        Current_TT          var long'general values to be written to the file
        Current_NOER        var LOng 
        Current_NOEN        var word 
        Current_NOER_last   var byte
    
    'hardware initialisation    
        SHTDWN = 0
        LED = 0
    'software initialisation, setting variables at their initial value
        TimerTick_max = 15000       'is 60 seconds    
        TimerTick_counter = 0       'Set counter to 0
        LED_blink_counter = 0       'For indicating error
        files_found = 0
        Current_TSO = 0
        Current_TSON = 0
        Current_TT = 0
        Current_NOER = 0
        Current_NOEN = 0
        
        
        pause 10000 
    'interrupt settings
    ASM
    INT_LIST  macro    ;    IntSource,  Label,                  Type,   ResetFlag?
             INT_Handler     TMR2_INT,   _TimerTick,             PBP,    yes           
        endm
        INT_CREATE                  ;Creates the interrupt processor
    ENDASM
    @ INT_ENABLE        TMR2_INT    ;enable Timer 2 interrupts
    
    '---[Main]----------------------------------------------------------------------
    Main:
        LED = 0                     'indicate start up procedure 
                                       
        gosub FSInit                'initialise the SD card
        Serout2 PORTB.1, 84, ["Init: ", FAT_error, " ", SDC_status, " ", SDC_response, $d, $a]
        gosub SD_error_check        'Check for errors on SD card
        gosub FINDfirst             'Look for files on SD card
        While(FAT_error = 0)        'Find next file on card
    		files_found = files_found + 1
    		Gosub FINDnext	       
    	Wend

  9. #9
    Join Date
    Apr 2016
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Hi Demon,

    Thanks for you private message. Only I cant reply with that and cant create my own.
    When i go to: "My profile" I get the following message:

    You have been banned for the following reason:
    No reason was specified.

    Date the ban will be lifted: Never
    Fortunally i can react on my own post, so that why I direct this "mail" to you in this way.
    If you have read it, it may be deleted because is has no further information to this kind
    of topic.

    With kind regards and helpful wishes,

    Remco

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,993


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Hi Remco.

    Try again and see your status. Hope is OK now.

    If not, Lester Please see the case.

    Ioannis

  11. #11
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    one problem i had when first getting sd card to work was cheep / ebay sd card slot holder
    i had micro sd card that was then fitted to standard sd card adapter

    changing the sd slot holder pcb allowed the sd card to work , it turned out 4 sd slot card holders did not hold the sd card well and would not allow initialization

    something to check / test

  12. #12
    Join Date
    Apr 2016
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    All of you, thank you for your help.

    But ofcource, as always, the code wasn't wrong (for now). My PCB layout was a tiny bit wrong with regards to the SD pinout.

    As they say, the devil is in the details

    Yet another little fact learned.

    But i will stay in touch, because I see other problem in the near furture.

    Kind regards,

    Rmeco

  13. #13
    Join Date
    Apr 2016
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    And here am i again,

    I am using the standard example from microengineering to write to a SD card.
    I can see that it's willing to create a new file, only when i want to write to it i
    get the error 9 (CE_WRITE_ERROR Con 9 ' Could not write to a sector).
    Am I blind to something or is it just so simple that i miss it?

  14. #14
    Join Date
    Apr 2016
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    And ofcource it was sutch a simple but rather irritating problem.

    Apperently the SDFS file or SD card doenst like a timer interrupt around the 4 ms.

    After removing this timer, is all worked an i could write to the file and read all of it.

    Thanks for the help anyway.

    Kind regards,

    Remco

  15. #15
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,983


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    You're welcome.

    This was research for my future use of SD cards. That sample code is perfect.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  16. #16
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    also even though he removed the timer, i wonder why it was using DT-INT-14,and not the int-18 version which is correct for the 18f chip sets

  17. #17
    Join Date
    Apr 2016
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: MMC/SD card initialization

    Al-tho it works fine (I see no difference in it't execution). And I actually never knew there was another file specially for pic18F and pic18LF. But I have changed it to the correct version now, thanks for the head-up.

Similar Threads

  1. Pin initialization question
    By rocket_troy in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th July 2012, 01:13
  2. SD or MMC card as storage for logging
    By HYETİK in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 16th January 2012, 03:07
  3. Really simple SD/MMC card socket
    By skimask in forum Schematics
    Replies: 12
    Last Post: - 23rd April 2008, 15:38
  4. PIC18F452 bootloader from MMC-card
    By Felch in forum Code Examples
    Replies: 2
    Last Post: - 20th January 2007, 12:26
  5. 18f452 initialization
    By Moldava in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th June 2004, 15:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts