It uses only 4 bit of GPIO port. No interrupt, no SPI port is used. The attached code is based on FatFs - Generic FAT File System Module (http://elm-chan.org/fsw/ff/00index_e.html).
And the sample MMC bitbanging code is taken from the zip file : http://elm-chan.org/fsw/ff/ffsample.zip
The changes to the generic sample code (mmcbb.c) are shown below.
Code: Select all
#define INIT_PORT() init_port() /* Initialize MMC control port (CS=H, CLK=L, DI=H, DO=in) */
#define DLY_US(n) bcm2835_delayMicroseconds(n) /* Delay n microseconds */
#define CS_H() bcm2835_gpio_set(RPI_GPIO_P1_26) /* Set MMC CS "high" */
#define CS_L() bcm2835_gpio_clr(RPI_GPIO_P1_26) /* Set MMC CS "low" */
#define CK_H() bcm2835_gpio_set(RPI_GPIO_P1_23) /* Set MMC SCLK "high" */
#define CK_L() bcm2835_gpio_clr(RPI_GPIO_P1_23) /* Set MMC SCLK "low" */
#define DI_H() bcm2835_gpio_set(RPI_GPIO_P1_19) /* Set MMC DI "high" */
#define DI_L() bcm2835_gpio_clr(RPI_GPIO_P1_19) /* Set MMC DI "low" */
#define DO bcm2835_gpio_lev(RPI_GPIO_P1_21) /* Test for MMC DO ('H':true, 'L':false) */
Code: Select all
void init_port(void) {
bcm2835_init();
bcm2835_gpio_fsel(RPI_GPIO_P1_23, BCM2835_GPIO_FSEL_OUTP); // CLK
bcm2835_gpio_clr(RPI_GPIO_P1_23);
bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_OUTP); // MOSI
bcm2835_gpio_set(RPI_GPIO_P1_19);
bcm2835_gpio_fsel(RPI_GPIO_P1_26, BCM2835_GPIO_FSEL_OUTP); // CE1
bcm2835_gpio_set(RPI_GPIO_P1_26);
bcm2835_gpio_fsel(RPI_GPIO_P1_21, BCM2835_GPIO_FSEL_INPT); // MISO
}
The data transfer rate will be several times slower than hardware SPI. I've just received a logic analyzer and I hope to build code for the SPI hardware soon.
For reference the SDCARD pinout :