FatFs library for sd card interace with PIC24FJ128GA010

Author
yo123
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
2019/01/10 07:43:53 (permalink)
0

FatFs library for sd card interace with PIC24FJ128GA010

hi,
i want to interface sd card with PIC24FJ128GA010 using FatFs library. i search some tutorial on google and i found that it is easy to configure SPI using MCC.  below function  is generated using MCC
clock=> FRC with FCY=8MHz
SPI1=>SPI1_Initialzation()   //125KHz
           SPI1_OPEN()     //2MHz this i inserted my own
void SPI1_Exchange( uint8_t *pTransmitData, uint8_t *pReceiveData )
{

    while( SPI1STATbits.SPITBF == true )
    {

    }

    SPI1BUF = *((uint8_t*)pTransmitData);

    while ( SPI1STATbits.SPIRBF == true);

    *((uint8_t*)pReceiveData) = SPI1BUF;

}

 
void SPI1_OPEN(void)
{
   // MSTEN Master; DISSDO disabled; PPRE 16:1; SPRE 2:1; MODE16 disabled; SMP Middle; DISSCK disabled; CKP Idle:Low, Active:High; CKE Active to Idle;
    SPI1CON1 = 0x13B;
    // SPIBEN enabled; SPIFPOL disabled; SPIFE disabled;
    SPI1CON2 = 0x00;
    // SPITBF disabled; SISEL SPI_INT_SPIRBF; SPIRBF disabled; SPIROV disabled; SPIEN enabled; SRXMPT disabled; SRMPT disabled; SPISIDL disabled; SPIBEC disabled;
    SPI1STAT = 0x800C;
}

 
to  disabled the Enhanced buffer mode
 after that  i checked the SPI using debugger , now i can see  that write function correct.
but did not check about  reading the SPI, please go through the SPI write function and correct me if am wrong for reading purpose.
uint8_t SPI1_Exchange8bit( uint8_t data )
{
    uint8_t receiveData;
    
    SPI1_Exchange(&data, &receiveData);

    return (receiveData);
}

 
after that i want to insert the FATFS function which attached below.
please suggest me, if  i have to edit anything in below file because i tried number of times but did not get
output.
thanking you
#1

2 Replies Related Threads

    yo123
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2017/04/19 09:52:08
    • Location: 0
    • Status: offline
    Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/11 07:19:56 (permalink)
    0
    hi all,
     so, when tried to mount the SD card , i got the error "FR_NOT_READY".
    after searching, it may because of following reason.
    • No medium in the drive.
    • Wrong lower layer implementation.
    • Wrong hardware configuration.
    • The storage device has broken.
    why this is happening?????
    the card is 4GB with FAT32 formatted and the card adapter is having 3.3 voltage shifter.
    please suggest your experience to solve this problem.
    thanking you.
    #2
    Aussie Susan
    Super Member
    • Total Posts : 3399
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/13 18:13:02 (permalink)
    0
    As you have not got an answer form someone who actually knows the answer (yet)...
    I seem to recall that FAT16 is about the most advanced format you can use. Try reformatting the SD card to FAT16 and see if that works.
    Susan
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5