21ic问答首页 - N32G430与STM32F407 SPI通信问题
N32G430与STM32F407 SPI通信问题
DaveMa2024-01-05
用STM32F407作为主机,N32G430作为从机,主机发送一个8位数据,从机通过SPI2接收并存到变量rec里。目前主机信号发送正常,从机程序每次都跑死在 while (SPI_I2S_Flag_Status_Get(SPI_SLAVE, SPI_I2S_FLAG_RNE) == RESET)这一步。查了用户手册说这个标志位会在接收数据后硬件清除,不知道怎么回事。贴出部分程序,求大神解答qwq。
SPI_Initializes_Structure(&SPI_InitStructure);
SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX;
SPI_InitStructure.SpiMode = SPI_MODE_SLAVE;
SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS;
SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW;
SPI_InitStructure.CLKPHA = SPI_CLKPHA_FIRST_EDGE;
SPI_InitStructure.NSS = SPI_NSS_SOFT;
/* It is recommended that the SPI master mode of the C version chips should not exceed 18MHz */
SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_8;
SPI_InitStructure.FirstBit = SPI_FB_MSB;
SPI_InitStructure.CRCPoly = 7;
SPI_Initializes(SPI2, &SPI_InitStructure);
SPI_Set_Nss_Level(SPI2, SPI_NSS_LOW);
SPI_CRC_Enable(SPI_SLAVE);
SPI_ON(SPI_SLAVE);
while (1)
{
while (SPI_I2S_Flag_Status_Get(SPI_SLAVE, SPI_I2S_FLAG_RNE) == RESET)
rec = SPI_I2S_Data_Get(SPI_SLAVE);
}
SPI_Initializes_Structure(&SPI_InitStructure);
SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX;
SPI_InitStructure.SpiMode = SPI_MODE_SLAVE;
SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS;
SPI_InitStructure.CLKPOL = SPI_CLKPOL_LOW;
SPI_InitStructure.CLKPHA = SPI_CLKPHA_FIRST_EDGE;
SPI_InitStructure.NSS = SPI_NSS_SOFT;
/* It is recommended that the SPI master mode of the C version chips should not exceed 18MHz */
SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_8;
SPI_InitStructure.FirstBit = SPI_FB_MSB;
SPI_InitStructure.CRCPoly = 7;
SPI_Initializes(SPI2, &SPI_InitStructure);
SPI_Set_Nss_Level(SPI2, SPI_NSS_LOW);
SPI_CRC_Enable(SPI_SLAVE);
SPI_ON(SPI_SLAVE);
while (1)
{
while (SPI_I2S_Flag_Status_Get(SPI_SLAVE, SPI_I2S_FLAG_RNE) == RESET)
rec = SPI_I2S_Data_Get(SPI_SLAVE);
}
您需要登录后才可以回复 登录 | 注册