hi, i'm new to PIC microcontrollers and will be using one (pic16f877a) to develop a project using an MMC/SD card.
i'm using an 8Mhz crystal, and i used the parameter SPI_CLK_DIV_4 for the setup_spi(), which means a 2Mhz SPi clock rate, and Tcy=1/2000000 sec (at least that's what i got from the datasheet) .anyway, for the MMC to power up it needs at least 1 msec for the supply ramp up time plus the power up time to get to VDD min (2.2 volts), my question is, how much clocks do i need to send to the MMC for it to completley power up?
my colleague told me that 80 clocks should be enough, but i don't think that would do the job, i mean :
80 x (1/2000000) is only 40 microsec ? , i probably need more than that, did i calculate the spi clock rate and Tcy correctly?
here's the code that i wrote (not all of it though, my problem is with the number of clocks to send (the FOR loop) ):
any anwsers would be much appreciated, thank you.
i'm using an 8Mhz crystal, and i used the parameter SPI_CLK_DIV_4 for the setup_spi(), which means a 2Mhz SPi clock rate, and Tcy=1/2000000 sec (at least that's what i got from the datasheet) .anyway, for the MMC to power up it needs at least 1 msec for the supply ramp up time plus the power up time to get to VDD min (2.2 volts), my question is, how much clocks do i need to send to the MMC for it to completley power up?
my colleague told me that 80 clocks should be enough, but i don't think that would do the job, i mean :
80 x (1/2000000) is only 40 microsec ? , i probably need more than that, did i calculate the spi clock rate and Tcy correctly?
here's the code that i wrote (not all of it though, my problem is with the number of clocks to send (the FOR loop) ):
Code:
int mmc_init()
{
int i;
SETUP_SPI(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4 | SPI_SS_DISABLED);
*0x94 |= 0x40; // set CKE = 1 - clock idle low
*0x14 &= 0xEF; // set CKP = 0 - data valid on rising edge
OUTPUT_HIGH(PIN_C2); // set SS = 1 (off)
for(i=0;i<10;i++) // initialise the MMC card into SPI mode by sending clks on
{
SPI_WRITE(0xFF);
}
OUTPUT_LOW(PIN_C2); // set SS = 0 (on) tells card to go to spi mode when it receives reset
SPI_WRITE(0x40); // send reset command
SPI_WRITE(0x00); // all the arguments are 0x00 for the reset command
SPI_WRITE(0x00);
SPI_WRITE(0x00);
SPI_WRITE(0x00);
SPI_WRITE(0x95); // precalculated checksum as we are still in MMC mode
puts("Sent go to SPI\n\r");
any anwsers would be much appreciated, thank you.