这是官方SPI例程中的代码,输入配置成GPIO_MODE_AF_PP,输出配置成GPIO_MODE_IN_PU,官方是在故意考验用户的解BUG能力吗
void SPI_FullDuplex_Init()
{
GPIO_Config_T gpioConfig;
SPI_Config_T spiConfig;
/* Enable related Clock */
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_SPI1);
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOA);
/* config PIN_6 MISO */
gpioConfig.pin = GPIO_PIN_6 ;
gpioConfig.mode = GPIO_MODE_AF_PP;
gpioConfig.speed = GPIO_SPEED_50MHz;
GPIO_Config(GPIOA, &gpioConfig);
/* config PIN_5->SCK , PIN_7->MOSI */
gpioConfig.pin = GPIO_PIN_5 | GPIO_PIN_7;
gpioConfig.mode = GPIO_MODE_IN_PU;
gpioConfig.speed = GPIO_SPEED_50MHz;
GPIO_Config(GPIOA, &gpioConfig);
SPI_ConfigStructInit(&spiConfig);
spiConfig.length = SPI_DATA_LENGTH_8B;
spiConfig.baudrateDiv = SPI_BAUDRATE_DIV_32;
/* 2 line full duplex */
spiConfig.direction = SPI_DIRECTION_2LINES_FULLDUPLEX;
/* LSB first */
spiConfig.firstBit = SPI_FIRSTBIT_LSB;
/* Slave mode */
spiConfig.mode = SPI_MODE_SLAVE;
/* Polarity is low */
spiConfig.polarity = SPI_CLKPOL_LOW;
/* Software select slave enable */
spiConfig.nss = SPI_NSS_SOFT;
/* Phase is 1 edge */
spiConfig.phase = SPI_CLKPHA_1EDGE;
/* SPI config */
SPI_Config(SPI1, &spiConfig);
SPI_ConfigDataSize(SPI1, SPI_DATA_LENGTH_8B);
SPI_Enable(SPI1);
} |