User manual

mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
391
Mmc_Init
Prototype
sub function Mmc_Init() as word
Description Initializes MMC through hardware SPI interface.
Mmc_Init needs to be called before using other functions of this library.
Parameters None.
Returns - 0 - if MMC/SD card was detected and successfully initialized
- 1 - otherwise
Requires The appropriate hardware SPI module must be previously initialized.
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.
Example
‘ MMC module connections
dim Mmc_Chip_Select as sbit at LATF0_bit for writing to output pin always
use latch (PIC18 family)
dim Mmc_Chip_Select_Direction as sbit at TRISF0_bit
‘ MMC module connections
dim error as byte
...
‘ 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)
‘ Loop until MMC is initialized
Mmc_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 None.