;) This forum is the property of Proton software developers

Main Menu

SD Card Fat16/Fat32

Started by pjdenyer, Jul 12, 2021, 12:58 PM

Previous topic - Next topic


This is a modified version of Les's code. I had to modify the FileName string length to correct file name error. All the function work apart from going back a directory, I have put a fix in the bas program which allows you to go back to the Root directory by re-initialising the SD Card.

If anyone has any ideas!!



I have a problem with the FileSys24 library and I can't detect vital signs using SD_File_System.bas.
I'm using a PIC24FJ64GA002 and the SPI bus is shared between the SD (1 GB FAT32), an external RAM and a DAC, each obviously driven by a dedicated CS line.
By picking up the signal with the logic state analyzer in parallel with the SD I verify the correct operation of both the RAM and the DAC, but when I try to use the SD I detect nothing.
I am using the file "SD_File_System.bas," and wanting to view directories and occupied and available space (pressing "1") I should see some traffic on the bus, I see only data on the serial communicator window (but no directory name), but I'm sure that data are wrong.
I have defined and rechecked the signals within the library a thousand times.
I don't understand where the problem could be!  :'(

Last update.
All wires re-routed, SD card changed and hours spent in debugging main code & library it goes !


Wilmax, was it just the wiring and type of sd card that caused the issue or were their any issues with the code I uploaded.


Make sure you have a pull-up resistor on the SD card's DOUT line.

It has been a long time since I worked with SD cards, but I remember the DOUT pin is Open-Drain, so it needs a pull-up resistor of about 10K on it, to the 3V3 line. Otherwise, nothing will be seen by the microcontroller.

I tend to place pull-up resistors on all the SD card's lines, just in case. :-)


Once the desperation has passed  ;D I re-routed and checked all wires, changed the SD card and now it works !
I have tried it with a 4 GB uSD and it works, same result with a 16 GB SD.
I still have problems with an old 1 GB SD that is not recognized, but it is correctly recognized by Windows if I insert it into an USB SD reader.


If a card is not operating correctly, go into the code and change the setup speed interface so it is slower.

For some inexplicable reason, SD cards need to be set up with a very slow SPI interface, then it is speeded up for normal operations once the setup is accepted? I've never understood this methodology with them because if the SPI interface is capable of higher speeds, why can't it be setup with that speed? It seems to be a trait from the MMC cards that pre-dated the SD cards.

Some cards need very slow interfaces when setting up, so the SPI speed in the code I wrote was "best guess", and is very slow. But it may not be slow enough for all cards.


Thank you Les! I will try!


To slow down the setup SPI interface speed, go into the SD_ReceiveByte and SD_SendByte procedures and change the DelayUs 4 commands, to a larger value for the delay.

Do it in increments of 1us until the SD card initialises.

To see if it is the SD not initialising or the FAT not initialising. Go into the FAT_Init() procedure, and place an HRsout command or a Print command between the code listing:

' Init SD/MMC
    If SD_InitSequence() = False Then
        Disk_tRWError = True
        Result = cErrNoResponse

If the code gives a signal, via the Hrsout or Print, from between the If-Endif statements, and just before it exits the procedure prematurely, it is the SD card that is not initialising because the SD_InitSequence() procedure has returned a false result.

Or look for an error of cErrNoResponse coming from the FAT_Init() procedure in your main code that calls it.