本帖最后由 walton1226 于 2020-7-15 09:09 编辑
#if 1 //single chip 0 is OK
{
status=PcdRequest(PICC_REQALL,ucInMF522Buf);//52
if(status)return 1;
status=PcdAnticoll(ucInMF522Buf);//93 20
if(status)return 1;
memcpy(ucUIDBuf,ucInMF522Buf,4);
status=PcdSelect1(ucUIDBuf);//93 70
if(status)return 1;
status=PcdHalt();//50
if(status)return 1;
}
#endif
SetBitMask(BitFramingReg,0x07);//send 7 bits
ucOutMF522Buf[0] = 0x40;
status = PcdComMF522(PCD_TRANSCEIVE,ucOutMF522Buf,1,ucOutMF522Buf,&unLen);
if((status != MI_OK) || (unLen != 4) || ((ucOutMF522Buf[0] & 0x0F) != 0x0A))return 1;
ClearBitMask(BitFramingReg,0x07);//send 8 bits
ucOutMF522Buf[0] = 0x43;
status = PcdComMF522(PCD_TRANSCEIVE,ucOutMF522Buf,1,ucOutMF522Buf,&unLen);
if((status != MI_OK) || (unLen != 4) || ((ucOutMF522Buf[0] & 0x0F) != 0x0A))return 1;
ucOutMF522Buf[0] = 0xa0;//write CMD
ucOutMF522Buf[1] = addr;//
CalulateCRC(ucOutMF522Buf,2,&ucOutMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE,ucOutMF522Buf,4,ucOutMF522Buf,&unLen);
if((status != MI_OK) || (unLen != 4) || ((ucOutMF522Buf[0] & 0x0F) != 0x0A))return 1;
for (i=0; i<16; i++)
ucOutMF522Buf =pdata;//write buffer
CalulateCRC(ucOutMF522Buf,16,&ucOutMF522Buf[16]);
status = PcdComMF522(PCD_TRANSCEIVE,ucOutMF522Buf,18,ucOutMF522Buf,&unLen);
if((status != MI_OK) || (unLen != 4) || ((ucOutMF522Buf[0] & 0x0F) != 0x0A))return 1;
//个人总结:UID卡的测试模式被放出来而已。
//40(7bits)+43(8bits)启动芯片的测试模式,之后用A0写命令写任意地址(addr)。
//前面的#if 0也可以写进去(附近只有单个芯片)。 |