Mikroelektronika MIKROE-724 データシート

ページ / 726
394
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Mmc_Fat_Init
Prototype
sub function Mmc_Fat_Init() as word
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 defined 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
 
dim Mmc_Chip_Select as sbit sfr at LATF0_bit
dim Mmc_Chip_Select_Direction as sbit sfr at TRISF0_bit
‘ MMC module connections
...
‘ 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 file system.