设置为主模式,只接收
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|RCC_APB1Periph_SPI2|RCC_APB1Periph_TIM2, ENABLE);
// Configure SPI2 pins: SCK, MISO ---------------------------- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure);
void SPI_Configuration(void) { SPI_InitTypeDef SPI_InitStructure; // SPI2 configuration ------------------------------------------------------ SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx; 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_Hard; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); // Enable SPI2 SPI_Cmd(SPI2, ENABLE); }
附上电路图,用SPI_I2S_SendData(SPI2,0xFF),用示波器没有检测到数据数据波及CLK波
|