描述:
我想知道spif位是在发送数据时给数据寄存器SPIDR赋值后会变为1,还是在接收数据的时候变为1. 因为我有看到这样的代码
void SPI_GetChar(U8 *pu8Char)
{
while(SPI_SR_SPIF==0);
*pu8Char=SPI_DR;
}
我认为这个代码说明,spif是在接收数据的时候应该变为1。但是为什么我这里接收的时候,始终跳不出while这个死循环呢?
解决方案1:
哦,datasheet 有点乱。那确实看不出问题来。你不跟踪的时候也会死吗?有可能这个原因:
Hello,
When processing a single byte at a time, such as with the previous code snippet, the period that SPTEF flag remains low will be very short, typically a few bus cycles only. During debug, it is therefore unlikely that you would ever observe the flag being cleared.
However, you should not single step through the function for another reason. The monitoring of the SPISR and SPIDR registers by the debugger can inadvertently cause the SPIF flag to be cleared prior to the wait loop being exited. The function will then never exit.
Regards,
Mac