level 1
小逃课13🍗
楼主
RC522初始化,寻卡,防冲突都成功 ,但是选卡,验证密钥失败
char PCD_Select(uint8_t *pSnr) {
char status;
uint8_t i;
uint16_t unLen;
uint8_t CmdFrameBuf[MFRC_MAXRLEN];
CmdFrameBuf[0] = PICC_ANTICOLL1;
CmdFrameBuf[1] = 0x70;
CmdFrameBuf[6] = 0;
for (i = 0; i < 4; i++) {
CmdFrameBuf[i + 2] = *(pSnr + i);
CmdFrameBuf[6] ^= *(pSnr + i);
}
MFRC_CalulateCRC(CmdFrameBuf, 7, &CmdFrameBuf[7]);
MFRC_ClrBitMask(MFRC_Status2Reg, 0x08);
status = MFRC_CmdFrame(MFRC_TRANSCEIVE, CmdFrameBuf, 9, CmdFrameBuf, &unLen);
if ((status == PCD_OK) && (unLen == 0x18)) {
status = PCD_OK;
} else {
status = PCD_ERR;
}
return status;
}
2022年06月18日 14点06分
1
char PCD_Select(uint8_t *pSnr) {
char status;
uint8_t i;
uint16_t unLen;
uint8_t CmdFrameBuf[MFRC_MAXRLEN];
CmdFrameBuf[0] = PICC_ANTICOLL1;
CmdFrameBuf[1] = 0x70;
CmdFrameBuf[6] = 0;
for (i = 0; i < 4; i++) {
CmdFrameBuf[i + 2] = *(pSnr + i);
CmdFrameBuf[6] ^= *(pSnr + i);
}
MFRC_CalulateCRC(CmdFrameBuf, 7, &CmdFrameBuf[7]);
MFRC_ClrBitMask(MFRC_Status2Reg, 0x08);
status = MFRC_CmdFrame(MFRC_TRANSCEIVE, CmdFrameBuf, 9, CmdFrameBuf, &unLen);
if ((status == PCD_OK) && (unLen == 0x18)) {
status = PCD_OK;
} else {
status = PCD_ERR;
}
return status;
}