Monday, February 3, 2025

Getting ESP-32 CAM with USB-C SD card to work

     Make this part 2 of a series, I suppose.  The high quality documentation of this device on the seller website marks 4 pins for use in the 'TF' column. TF stands for Trans-Flash, and apparently is a lesser used term for SD card. The savvy SD card user may note that no function is denoted for any of the 4 pins in the 'TF' column.


    A little searching finds that SPI pins can be reassigned.  The following snippet is from the SD card test example:

...

/* Uncomment and setup pins you want to use for the SPI communication #define REASSIGN_PINS int sck = -1; int miso = -1; int mosi = -1; int cs = -1; */

...

#ifdef REASSIGN_PINS SPI.begin(sck, miso, mosi, cs); if (!SD.begin(cs)) { #else if (!SD.begin()) {

    Sometimes brute force is the easiest way, and an approach can be made when realizing that there are only 4! = 24 possible combinations, then trying them one at a time. 

    Surely a programmatic approach could attempt to mount the card with each combination; this exercise is left to the reader.  I preferred just hand jamming one combination, compiling, checking if the card mount failed, and then moving to the next combination. But, failure upon trying the last combination brought me back to the seller provided documentation. The zip file provided by the seller contained a very slightly different pin mapping.

    While still leaving a little ambiguity, I guessed 'CLK' denotes clock (sck) and 'CMD' chip select (cs), just leaving the meanings of 'DAT0' and 'DAT3' to be identified.  I will stop holding dear readers in suspense and just reveal the working pin assignment.  

...
#define REASSIGN_PINS
int sck = 4;
int miso = 13;
int mosi = 21;
int cs = 19;
...
(Looks like it took only 4 tries into hand jamming before I got mixed up, skipping over the working pin mapping, whoops!)

***An update after first publication, it seems that the assumption that CMD maps to cs is NOT correct in the wider world of SD card SPI pin mappings.  Regardless, the pinout reported above does succeed in mounting the SD card and performing the read/write operations of the SD_test example, so maybe the documentation is wrong and I got lucky?

No comments:

Post a Comment