2015-03-01 08:59 PM
when i use SPI to receiver a byte from the external ADC chip, but the SPI_SR_RXNE can't be set after the data into the SPI_DR.the initialization code below:
void MX_SPI2_Config(void){ /* Enable the peripheral clock SPI2 */ RCC->APB1ENR |= RCC_APB1ENR_SPI2EN; /* DISABLE TXE IT */ SPI2->CR2 &= ~(SPI_CR2_TXEIE | SPI_CR2_RXNEIE | SPI_CR2_ERRIE | SPI_CR2_FRF | SPI_CR2_SSOE | SPI_CR2_TXDMAEN | SPI_CR2_RXDMAEN); /* MASTER MODE, SCK IDLE HIGH */ SPI2->CR1 |= (SPI_CR1_MSTR | SPI_CR1_CPOL); /* NSS SOFT */ SPI2->CR1 |= (SPI_CR1_SSM | SPI_CR1_SSI); /* RXNE IT */ SPI2->CR2 |= SPI_CR2_RXNEIE; /* 16 bit frame mode */ SPI2->CR1 |= SPI_CR1_DFF; /* Enable SPI2 */ SPI2->CR1 |= SPI_CR1_SPE; /* Configure IT */ /* Set priority for SPI2_IRQn */ NVIC_SetPriority(SPI2_IRQn, 0); /* Enable SPI2_IRQn */ NVIC_EnableIRQ(SPI2_IRQn); }void SPI2_IRQHandler(void){ if((SPI2->SR & SPI_SR_RXNE) == SPI_SR_RXNE) { SPI2_Data = SPI2->DR; }}