/******************************************************************************* MicroSD initialization return: 0x00=success *******************************************************************************/ u8 MSD_Init(void) { u32 i=0; SPI_Config(); MSD_CS_HIGH(); for(i=0; i <10; i++) MSD_WriteByte(DUMMY); //Send dummy byte: 8 Clock pulses of delay return MSD_GoIdleState(); }
u8 MSD_Init(void) { u32 i = 0; /* Initialize SPI1 */ spi_init(); /* MSD chip select high */ spi_ss(_FLASH_NUM0,1); /* Send dummy byte 0xFF, 10 times with CS high*/ /* rise CS and MOSI for 80 clocks cycles */ for (i = 0; i <= 9; i++) { /* Send dummy byte 0xFF */ spi_send(DUMMY); } /*------------Put MSD in SPI mode--------------*/ /* MSD initialized and set to SPI mode properly */ return (MSD_GoIdleState()); }
/******************************************************************************* * Function Name : MSD_Init * Description : Initializes the MSD/SD communication. * Input : None * Output : None * Return : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed * - MSD_RESPONSE_NO_ERROR: Sequence succeed *******************************************************************************/ u8 MSD_Init(void) { u32 i = 0; RCC->APB2ENR|=1<<2; //PORTA时钟使能 GPIOA->CRL&=0XFFF000FF; GPIOA->CRL|=0X00033300;//PA2.3.4 推挽 GPIOA->ODR|=0X7<<2; //PA2.3.4上拉 SPIx_Init(); SPIx_SetSpeed(SPI_SPEED_256);//设置到低速模式 /* MSD chip select high */ Set_SD_CS; /* Send dummy byte 0xFF, 10 times with CS high*/ /* rise CS and MOSI for 80 clocks cycles */ for (i = 0; i <= 9; i++) { /* Send dummy byte 0xFF */ MSD_WriteByte(DUMMY); } /*------------Put MSD in SPI mode--------------*/ /* MSD initialized and set to SPI mode properly */ return (MSD_GoIdleState()); }