读写SD卡
读写SD卡用EKSTM32F开发板,SPI1连接SD卡,USART1用于调试。具体硬件连接图可参考万利提供的原理图。源代码如下:/*filename:MMC_SD.c*/#include"stm32f10x_lib.h"#include"mmc_sd.h"#include"usart.h"#defineTIMEOUT1#defineMMC_SD_SPI_SELECT()GPIO_ResetBits(GPIOD,GPIO_Pin_9)#defineMMC_SD_SPI_DESELECT()GPIO_SetBits(GPIOD,GPIO_Pin_9)#defineMMC_SD_POWERON()GPIO_ResetBits(GPIOD,GPIO_Pin_10)voidMMC_SD_SPI_Config(void){SPI_InitTypeDefSPI_InitStructureGPIO_InitTypeDefGPIO_InitStructureRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO|RCC_APB2Periph_SPI1,ENABLE)/*ConfigureSPI1pins:NSS,SCK,MISOandMOSI*/GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7