1、STM32F207 使用SPI2收不到数据的问题 问:我使用STM32F207的SPI2控制模数转换器AD977时, STM32F207处理器的SPI2工作在单向只接收模式(从模式)下,我的SPI2总是接收不到数据(但在SPI2_MOSI管脚上有数据,时钟也有,我用示波器看的),请帮我分析一下。我的SPI及管脚配置如下: void SPI2_Config(void) { //NVIC_InitTypeDef NVIC_InitStructure; /* Enable the SPI clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); /* Enable GPIO clocks */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* Connect SPI pins to AF5 */ //GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2); //GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2); //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; /* SPI SCK pin configuration */ //GPIO_InitStructure.GPIO_Pin =GPIO_Pin_13; //GPIO_Init(GPIOB, &GPIO_InitStructure); /* SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(GPIOB, &GPIO_InitStructure); /* SPI configuration -------------------------------------------------------*/ SPI_I2S_DeInit(SPI2); SPI_Cmd(SPI2, DISABLE); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode=SPI_Mode_Slave; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; <span style="font-size: 10.5pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">SPI2->CR1=0 |
RE:关于STM32的SPI问题集锦
RE:关于STM32的SPI问题集锦
RE:关于STM32的SPI问题集锦
RE:关于STM32的SPI问题集锦
void SPI_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_Cmd(SPI1, DISABLE);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设置SPI工作模式:设置为主SPI
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //设置SPI的数据大小:SPI发送接收8位帧结构
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //选择了串行时钟的稳态:时钟 悬空低
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //数据捕获于第二个时钟沿
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS信号由硬件(NSS管脚)还是 软件(使用SSI位)管理:内部NSS信号有SSI位控制
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //定义波特 率预分频的值:波特率预分频值为256
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC值计算的多项式
SPI_Init(SPI1, &SPI_InitStructure); //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
SPI_Cmd(SPI1, ENABLE); //使能SPI外设
}
/***Dataflash_write2flash()*****连续写数据到SPI Flash内部**************/
Dataflash_write2flash(unsigned char* data, unsigned int page, unsigned int address, unsigned int size, FLASH_BUFFER_NUM buffer_num)
{
u16 i;
if(SPI_Data_Flash_Busy_Detect()==0) //==0 Data Flash空闲
{
SPI_Data_Flash_AT_SELECT(); //片选Dataflash
if(buffer_num == FLASH_BUFFER1)
SPI_ReadWrite_Byte(AT45DB_BUFFER_1_WRITE_FLASH );
else
SPI_ReadWrite_Byte(AT45DB_BUFFER_2_WRITE_FLASH);
SPI_ReadWrite_Byte(page>>5);
SPI_ReadWrite_Byte((page8));
SPI_ReadWrite_Byte(address);
for (i=0; i