• AVR Freaks

SD card SPI 6012A troubleshooting

Page: < 12 Showing page 2 of 2
Miroslav Segvic
Senior Member
  • Total Posts : 167
  • Reward points : 0
  • Joined: 2013/05/27 06:53:43
  • Location: Zagreb, Croatia
  • Status: offline
Re: SD card SPI 6012A troubleshooting 2015/01/20 14:41:03 (permalink)
4.5 (2)
Solution: Forgot to connect 5V to sd card module. (Excuse: module mounted under the second panel, not visible from outside)
Answers to many questions from above regarding dspic30F and SD card module, and fileIO library, SPI library and driver:
  • SD-card module MLA library works with high frequency oscillator.
  • Changes to the system.c necessary if not using Card detect pin (modules don't have them)
inline bool USER_SdSpiGetCd_1(void) //card detect function
    //return (!PORTFbits.RF0) ? true : false; // commented this
    return 1; // added this 

  • Changes to system.c necessary if not using write protect pin(modules don't have them)
inline bool USER_SdSpiGetWp_1(void)
    //return (PORTFbits.RF1) ? true : false;
      return 0;

  • Wont mount drive with Enhanced buffer enabled. Add the device in file drv_spi_16bit.c
#if defined(__dsPIC30F6012A__) || defined(__PIC24FJ128GA010__) || defined(__PIC24FJ96GA010__) || defined(__PIC24FJ64GA010__) || defined(__PIC24FJ128GA008__) || defined(__PIC24FJ96GA008__) || defined(__PIC24FJ64GA008__) || defined(__PIC24FJ128GA006__) || defined(__PIC24FJ96GA006__) || defined(__PIC24FJ64GA006__)
  #pragma message "DRV_SPI_CONFIG_ENHANCED_BUFFER_DISABLE is automatically enabled because SPI FIFO mode is not supported on this device."

  • Change register names in drv_spi.h example for 6012A below

/* SPI SFR definitions. i represents the SPI
   channel number.
   valid i values are: 1, 2, 3
   for PIC24/32 device families
    #define DRV_SPI_STAT(i) SPI1STAT
    #define DRV_SPI_STATbits(i) SPI1STATbits
    #define DRV_SPI_CON(i) SPI1CON
    #define DRV_SPI_CONbits(i) SPI1CONbits
    #define DRV_SPI_CON2(i) SPI2CON
    #define DRV_SPI_CON2bits(i) SPI2CONbits
    #define DRV_SPI_BUF(i) SPI1BUF
    #define DRV_SPI_BUFbits(i) SPI1BUFbits

  • Change system.h for clock frequency. Timer information not needed(although i'm already running timer1 at 400Hz for other purpose). Example for 6012A at 30MIPS(15Mhz with PLL8)
// Definition for system clock
#define SYS_CLK_FrequencySystemGet() 120000000
// Definition for peripheral clock
#define SYS_CLK_FrequencyPeripheralGet() SYS_CLK_FrequencySystemGet()
// Definition for instruction clock
#define SYS_CLK_FrequencyInstructionGet() (SYS_CLK_FrequencySystemGet() / 2)

  • There are some include statements needed to change the path, but compiler will warn you about that.
  • Trickiest part was to get all the files necessary for library to run. Since files are from fileIO library and SPI library, and Driver folderSo i used MLA 2014_07_22 and this is complete list of files necessary to get me here(they are scattered around the MLA folders):
    • drv_spi.h
    • drv_spi_config.h
    • fileio.h
    • fileio_config.h
    • fileio_private.h
    • sd_spi.h
    • sd_spi_config.h
    • sd_spi_private.h
    • system.h
    • system_config.h
    • drv_spi_16bit.c
    • fileio.c
    • sd_spi.c
    • system.c
That is all. Small tutorial for adapting the library to work with dspic30f6012A
EDIT: And used fat32 formatted card to get 512byte sector on 1gb card
Thanks for help everyone.
Best regards
post edited by Miroslav Segvic - 2015/01/20 18:01:41
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5