|
本帖最后由 andy93762 于 2018-4-17 11:05 编辑
最近这个项目需要读取二代身份证卡号,一般用RC523或者FM17550芯片都可以实现,因为同时支持TYPEB和TYPEA协议。
TYPEA协议的IC卡很简单,一下子就调试通了,但是身份证就是死活没法识别出来,应该哪里没有配置好。第一步寻卡函数RCRequestTypeB就没法返回成功状态
有做过的朋友麻烦帮忙下,万分感谢。
初始化配置如下:
ClearBitMask(Status2Reg, 0x08);
WriteRawRC(ModeReg, 0x3F); // For 0xFFFF crc
WriteRawRC(TReloadRegL, 30);
WriteRawRC(TReloadRegH, 0);
WriteRawRC(TModeReg, 0x8D);
WriteRawRC(TPrescalerReg, 0x3E);
WriteRawRC(TxAutoReg, 0); // Force 100ASK = 0
WriteRawRC(GsNReg, 0xFa);
WriteRawRC(CWGsPReg, 0x3F);
WriteRawRC(ModGsPReg, 0x2a);
//WriteReg(ModGsPReg, 0x1A);
WriteRawRC(TxModeReg, 0x83);
WriteRawRC(BitFramingReg, 0x00);
WriteRawRC(AutoTestReg, 0x00);
WriteRawRC(TypeBReg, 0xc0);
WriteRawRC(ModWidthReg,0x68);
WriteRawRC(DemodReg, 0x5D);
WriteRawRC(RFCfgReg, 0x70); // 0x59 RegRxControl1//73,
WriteRawRC(RxModeReg, 0x83);
WriteRawRC(RxThresholdReg, 0x65);//0x75);
ClearBitMask(RxSelReg,0x3F); // TR0
SetBitMask(RxSelReg, 0x08);
ClearBitMask(TxModeReg, 0x80); // ?CRC
ClearBitMask(RxModeReg, 0x80);
ClearBitMask(Status2Reg, 0x08); // MFCrypto1On =0
PcdAntennaOn();
uint8_t RCRequestTypeB(void)//寻卡
{
uint8_t status;
unsigned int len;
uint8_t buf[18] = {0};
buf[0] = 0x05;
buf[1] = 0x00;
buf[2] = 0x00;
buf[3] = 0x71;
buf[4] = 0xFF;
status = PcdComMF522(PCD_TRANSCEIVE, buf, 5, buf, &len);
return status;
}
uint8_t RCATTRIBTypeB(u8 *PSN)
{
uint8_t status;
unsigned int len;
uint8_t buf[18] = {0};
buf[ 0] = 0x1D; // 1d 00 00 00 00 00 08 01 08
buf[ 1] = 0x00; // PUPI
buf[ 2] = 0x00;
buf[ 3] = 0x00;
buf[ 4] = 0x00;
buf[ 5] = 0x00;
buf[ 6] = 0x08;
buf[ 7] = 0x01;
buf[ 8] = 0x08;
buf[ 9] = 0xF3; // crc
buf[10] = 0x10;
//RC_CalulateCRC(buf, 9, &buf[9]);
status = PcdComMF522(PCD_TRANSCEIVE, buf, 11, PSN, &len);
return status;
}
uint8_t RCGetUIDTypeB(u8 *pUID)
{
uint8_t status;
unsigned int len;
uint8_t buf[18] = {0};
buf[0] = 0x00;
buf[1] = 0x36;
buf[2] = 0x00;
buf[3] = 0x00;
buf[4] = 0x08;
buf[5] = 0x57; // crc
buf[6] = 0x44;
//RC_CalulateCRC(buf, 5, &buf[5]);
status = PcdComMF522(PCD_TRANSCEIVE, buf, 7, buf, &len); // ??????????UID "....9000"
if (status == 0)
{
//memcpy(pUID, buf, 10);
}
return status;
}
char RC522_ReadID_B(unsigned char *PSN) //读写二代身份证函数
{
char i,status;
status = RCRequestTypeB();
if (status == MI_OK)
{
status = RCATTRIBTypeB(PSN);
if (status == MI_OK)
{
status = RCGetUIDTypeB(PSN);
if (status == MI_OK)
{
i++;
}
}
}
return status;
}
|
|