最近遇到一个和这个相关的问题也是只能读,写不进去。软件模拟spi通信。
楼主帮忙看一下这段写数据有什么问题,谢谢
static void WriteRawRC(u8 Address, u8 value)
{
u8 i, ucAddr;
RC522_SCK_CRL; //MF522_SCK = 0;
RC522_SDA_CRL; //MF522_SDA = 0;
ucAddr = ((Address << 1) & 0x7E);
for (i = 8; i > 0; i--)
{
//MF522_MOSI = ((ucAddr & 0x80) == 0x80);
if (0x80 == (ucAddr & 0x80))
RC522_MOSI_SET;
else
RC522_MOSI_CRL;
RC522_SCK_SET; //MF522_SCK = 1;
delay_us(10);
ucAddr <<= 1;
RC522_SCK_CRL; //MF522_SCK = 0;
}
for (i = 8; i > 0; i--)
{
//MF522_MOSI = ((value&0x80)==0x80);
if (0x80 == (value & 0x80))
RC522_MOSI_SET;
else
RC522_MOSI_CRL;
RC522_SCK_SET; //MF522_SCK = 1;
delay_us(10);
value <<= 1;
RC522_SCK_CRL; //MF522_SCK = 0;
}
RC522_SDA_SET; //MF522_SDA = 1;
RC522_SCK_SET; //MF522_SCK = 1;
} |