CR2一定要设置成0x03;
硬件SPI的端口貌似无需初始化。
参考一下我的程序吧:void spi_init(void)
{
SPI->CR1=SPI_CR1_SPE|/*SPI_CR1_CPHA|SPI_CR1_CPOL|*/SPI_CR1_MSTR|(3<<3); //16分频
SPI->CR2=SPI_CR2_SSM|SPI_CR2_SSI; //软件模式控制使能引脚
//SPI->CR1|=SPI_CR1_SPE;//SPI开启
}
uint8_t spi_rw_byte(uint8_t dat)
{
while(!(SPI->SR & SPI_SR_TXE));
SPI->DR=dat;
while(!(SPI->SR&SPI_SR_RXNE));
return SPI->DR;
}
|