我用两块stm32做了个spi通讯,都用spi1,一个主发送,一个从中断接收。最开始的时候两个板子都没焊其它器件。通讯正常。后来逐渐的焊上了其他的器件,也有用spi通讯的器件。最后我又再测试spi通讯,结果不正常了。接收到的全是0,为了验证是不是程序的问题,我把所有不相干的程序都屏蔽掉,并且把所有用到spi接口的芯片的片选都拉高,还是不行。用示波器测了一下波形,波形都有,就是觉得没有以前规整。我现在搞不清除了,我的从接收还是能够进入中断的,即使波形不规整,既然能够进入中断,多少有个数也行啊,乱的也行啊。可是全是0.我郁闷的不行。现在又不想把其余的器件取下来测试,哪位有经验帮帮忙。下面是初始化程序
主
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
从
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/* Enable SPI1 RXNE interrupt */
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);
/* Enable SPI1 */
SPI_Cmd(SPI1, ENABLE); |