PIC32模拟spi,读出数据移位了,写正常。
UINT8 SWReadSPI_BCO(void)
{
UINT8 i;
UINT8 ReceivedByte;
SET_SPIDO_H;
ReceivedByte = 0;
for (i=0; i<8; i++)
{
SET_SPICLK_L;
CLK_LOW_DELAY;
ReceivedByte <<= 1;
SET_SPICLK_H;
if (READ_SPIDI)
ReceivedByte |= 0x01;
else
ReceivedByte &= ~0x01;
}
SET_SPICLK_H;
return (ReceivedByte);
}
比如正确的数据是0x01,0x48,0x9f,0x01,但是读出确是0x80,0xa4,0x4f,0x80 |