用同一块板子上的SPI1为主,SPI2为从,然后各个管脚用飞线连接,如果SPI2收到正确的数据,则中断,LED状态翻转,为什么SPI1发不出数据呢,SPI1的DR寄存器始终为0(也进不去中断),用示波器看SPI1的管脚,没有任何信号,这是部分代码
void SPI_Configration(void)
{
SPI_InitTypeDef SPI_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 ,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 ,ENABLE);
SPI_I2S_DeInit(SPI1);
SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
SPI_InitStruct.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;
SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CRCPolynomial = 7;
SPI_Init(SPI1,&SPI_InitStruct); //初始化SPI1为主设备
SPI_InitStruct.SPI_Mode = SPI_Mode_Slave;
SPI_Init(SPI2,&SPI_InitStruct); //初始化SPI2为从设备
SPI_I2S_ITConfig(SPI2,SPI_I2S_IT_RXNE, ENABLE);
SPI_Cmd(SPI2,ENABLE);
SPI_Cmd(SPI1,ENABLE);
void GPIO_Configration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB ,ENABLE);
/*****初始化LED***********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化LED0端口
/***********初始化主设备SPI1*********/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA,&GPIO_InitStructure);
/***********初始化从设备SPI2*******************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_14| GPIO_Pin_15; //SCK
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
还有一个问题就是仿真的时候,打开SPI1的寄存器看到,NSS为DISABLE,这又是什么问题呢
} |