FatFs library for sd card interace with PIC24FJ128GA010
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_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;
// 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 )
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