各位大虾好,
下面这个是我用的SPI1的重映射,我的SD卡SPI通信口就是链接到这几个口上面的,在调用Mass_Storage_Start ();函数时总是检测不到SD卡,能帮我看下void SPI_Config(void)程序什么问题?谢谢!
void Mass_Storage_Start (void)
{
/* Disble the JoyStick interrupts */
IntExtOnOffConfig(DISABLE);
/* Clear the OLED screen */
//OLED_Clear(White);
/* Set the Back Color */
OLED_SetBackColor(Blue);
/* Set the Text Color */
OLED_SetTextColor(White);
if(MSD_Init() != 0x00)
{
OLED_DisplayStringLine(Line0, "Warning ");
OLED_DisplayStringLine(Line1, " NO ");
OLED_DisplayStringLine(Line2, "SD Card ");
OLED_DisplayStringLine(Line3, "Pres SEL");
/* Loop until SEL key pressed */
while(ReadKey() != SEL)
{
}
}
else
{
Get_Medium_Characteristics();
OLED_Clear(White);
/* Display the " Plug the USB " message */
OLED_DisplayStringLine(Line1, " Plug ");
OLED_DisplayStringLine(Line2, "USB Cable");
/* Intialize the USB cell */
USB_Init();
//OLED_ClearLine(Line9);
/* Display the "To stop Press SEL" message */
//OLED_DisplayStringLine(Line8, " To stop Press SEL ");
/* Loop until SEL key pressed */
while(ReadKey() != SEL)
{
}
PowerOff();
}
OLED_Clear(White);
//DisplayMenu();
IntExtOnOffConfig(ENABLE);
/* Flush SPI1 Data Register */
SPI_ReceiveData(SPI1);
}
void SPI_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/* GPIOB Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
/* SPI1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
/* Configure SPI1 output pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure SPI1 input pin: MISO */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure PB6 pin: CS pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* SPI1 Periph Remap */
GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);
/* SPI1 Config */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/*Enable SPI1.NSS as a GPIO*/
//SPI_SSOutputCmd(SPI1, ENABLE);
/* SPI1 enable */
SPI_Cmd(SPI1, ENABLE);
} |