0
我在驗證我的mifare卡時遇到問題。在數據表中寫入默認密鑰是0xFFFFFFFFFFFF
,但它不起作用。我不知道什麼是錯的,如果有人能幫助我。RC522默認密鑰
這是我的代碼,我想補充說,檢查卡是正確的,工作正常。
main.c中:
#include "spi.h"
#include <stdio.h>
#include "oldrc522.h"
int main(void) {
uint8_t CARD_ID[5];
uint8_t KEY[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uint8_t MY_CARD[5]={0x19,0x5a,0xcc,0xac,0x23};
TM_MFRC522_Init();
printf("INIT\n\n\n");
while(1){
if (TM_MFRC522_Check(CARD_ID) == MI_OK) {
//CardID is valid
//Check if this is my card
if (TM_MFRC522_Compare(CARD_ID, MY_CARD) == MI_OK) {
printf("HELLO!\n\n");
if((TM_MFRC522_Auth(PICC_AUTHENT1A,7,KEY,MY_CARD) == MI_OK))
printf("OK");
else printf("FAILED\n\n");
} else
printf("INVALID CARD\n\n");
} else {
//Some printing to delete content
}
}
}
TM_MFRC522_Auth功能:
TM_MFRC522_Status_t TM_MFRC522_Auth(uint8_t authMode, uint8_t BlockAddr, uint8_t* Sectorkey, uint8_t* serNum) {
TM_MFRC522_Status_t status;
uint16_t recvBits;
uint8_t i;
uint8_t buff[12];
//Verify the command block address + sector + password + card serial number
buff[0] = authMode;
buff[1] = BlockAddr;
for (i = 0; i < 6; i++) {
buff[i+2] = Sectorkey[i];
}
for (i=0; i<4; i++) {
buff[i+8] = serNum[i];
}
status = TM_MFRC522_ToCard(PCD_AUTHENT, buff, 12, buff, &recvBits);
if ((status != MI_OK) || (!(TM_MFRC522_ReadRegister(MFRC522_REG_STATUS2) & 0x08))) {
status = MI_ERR;
}
return status;
}
「但它不起作用」你能更具體嗎?哪個功能失敗? – purplepsycho