User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
369
Mmc_Fat_Init
Prototype
unsigned int Mmc_Fat_Init();
Description Initializes MMC/SD card, reads MMC/SD FAT16 boot sector and extracts necessary data needed by
the library.
Parameters None.
Returns - 0 - if MMC/SD card was detected and successfully initialized
- 1 - if FAT16 boot sector was not found
- 255 - if MMC/SD card was not detected
Requires Global variables :
- Mmc_Chip_Select: Chip Select line
- Mmc_Chip_Select_Direction: Direction of the Chip Select pin
must be dened before using this function.
The appropriate hardware SPI module must be previously initialized. See the SPIx_Init, SPIx_Init_
Advanced routines.
Example
// MMC module connections
sbit Mmc_Chip_Select at LATF0_bit;
sbit Mmc_Chip_Select_Direction at TRISF0_bit;
// MMC module connections
#include <spi_const.h>
...
// Initialize the SPI module
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_
PRESCALE_PRI_64,_SPI_SS_DISABLE,
_SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_
IDLE);
// Initialize MMC/SD card and MMC_FAT16 library globals
Mmc_Fat_Init();
// Reinitialize the SPI module at higher speed (change primary prescaler).
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_
PRESCALE_PRI_4,_SPI_SS_DISABLE,
_SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_
IDLE);
Notes MMC/SD card has to be formatted to FAT16 le system.