SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* SPI2 Periph clocks enable */ RCC_APB1PeriphClockCmd (RCC_APB1Periph_SPI2, ENABLE); /* GPIOB clock enable */ RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO, ENABLE); /* SCK, MISO and MOSI PB13=CLK,PB14=MISO,PB15=MOSI*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); /* PB12 作片选*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_12); //预置为高 /* SPI1 configuration */ SPI_Cmd(SPI2, DISABLE); //必须先禁能,才能改变MODE SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //两线全双工 SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //主 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //8位 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //CPOL=0 时钟悬空低 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //CPHA=0 数据捕获第1个 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //软件NSS SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //4分频=9M < 25M (LOW READ) SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //高位在前 SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); SPI_Cmd(SPI2, ENABLE); 这是简单的配置 然后发送字节这样 uint8_t SPI_SendByte(uint8_t data) { while((SPI2->SR & SPI_I2S_FLAG_TXE)==RESET); /*等待发送寄存器空*/ SPI2->DR = data; /*发送一个字节*/ while((SPI2->SR & SPI_I2S_FLAG_RXNE)==RESET); /* 等待接收寄存器有效*/ return(SPI2->DR); }、 然后测试发送的时候,用示波器总是看不到波波、 |
回复:spi发送不了,亲们,帮我看看
回复:spi发送不了,亲们,帮我看看