STM32 的SPI2是能后,当发送一个数据后,没有接受到数据RXNE标志置1,因为采用万利实验板,没有接spi线,肯定是没有接收导数据的,主要设置如下:
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_15; //SPI2_SCK/SPI2_MOSI
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_14; //SPI2_MISO
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
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_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStructure);
设置好后, SPI_Cmd(SPI2, ENABLE);
GPIO_SetBits(GPIOC, GPIO_Pin_7); //点亮led1
SPI_I2S_SendData(SPI2, 49);
while(SPI_I2S_GetFlagStatus( SPI2, SPI_I2S_FLAG_RXNE)==RESET); //
SPI_RX=SPI_I2S_ReceiveData(SPI2);
GPIO_SetBits(GPIOC, GPIO_Pin_5);//点亮led3
while(SPI_I2S_GetFlagStatus( SPI2, SPI_I2S_FLAG_TXE)==RESET);
SPI_I2S_SendData(SPI2, 50);
问题就在 有了SPI_I2S_SendData(SPI2, 49);这一句发送后,RXNE就会置位,while(SPI_I2S_GetFlagStatus( SPI2, SPI_I2S_FLAG_RXNE)==RESET); 这句就会执行过去,
如果没有发送语句RXNE是复位的,我用中断方式结果还是一样的,只要有发送语句就会进RXNE的中断,不知道什么原因?
|