Maker Pro
Maker Pro

Reading/Writing to SD card using Petit FatFs?


Sep 27, 2012
Sep 27, 2012
Hello guys,

I am currently trying to read/write to my sd card using the Petit FatFs System found here:

I am using MPLAB with a PIC18F14K50 to talk to the 8GB MicroSD card using SPI.

I am using the sample code for the pic24 that is given at the bottom of the Petit FatFs website (found under "Resources" on the website ). From what I understand I don't really need to change anything other than the platform dependent macros in the code.

That means, I only need to edit the files: pff.h and and diskio.c to fit my pic18.
Having done that, I still can't write anything to the SD card!

The program seems to be stuck somewhere inside the "disk_initialize" function. I dont use UART and since I am using a PIC18F14K50 I can't debug it using the MPLAB debugger. I have been trying to debug it visually, by turning on an LED on my low pin count development board after a function executes (it enters an infinate while loop).

Can you guys see anything wrong in the code that I have written, because at this point I am out of ideas!

The PIC24 Sample code is attached and my code is attached as well.

Hope you can help!


Ok, so I have now tried to debug the code and found out that in the disk_initilize function, the program is stuck inside xmit_spi (inside the while loop). This can be found inside diskio.c

It seems like the buffer Full "BF" bit inside SSPSTAT is always 0 and hence the program never exits...

Any idea's how to fix this?

PS: Please download the files from here: