CR95F X-Nucleo NFC03A1 Shield STM
Dependents: Nucleo_NFC03A1_Demo
Diff: CR95HF.cpp
- Revision:
- 3:12c871b2412d
- Parent:
- 2:c7006765c441
- Child:
- 4:8fce71523e13
diff -r c7006765c441 -r 12c871b2412d CR95HF.cpp --- a/CR95HF.cpp Fri Aug 31 06:33:12 2018 +0000 +++ b/CR95HF.cpp Mon Sep 03 15:09:39 2018 +0000 @@ -18,30 +18,51 @@ uint8_t CR95HF::Init() { uint8_t commandInfo[] = {0x01, 0x00}; - uint8_t commandSetProtocoll[] = {0x02, 0x01, 0x02, 0x00}; + uint8_t commandSetProtocoll[] = {0x02, 0x02, 0x01, 0x05}; printf("CR95HF_Init\r\n"); nfcDevice.baud(57600); - nfcDevice.attach(this, &CR95HF::rxCallbackNFC); - wait(1); nfcWrite(commandInfo, 2); wait(1); nfcWrite(commandSetProtocoll, 4); - + wait(1); + nfcDevice.attach(this, &CR95HF::rxCallbackNFC, Serial::RxIrq); return(0); } uint8_t CR95HF::ConfigManagerTagHunting() { uint8_t returnValue = false; + uint8_t detectCard[] = {0x04, 0x03, 0x26, 0x01, 0x00}; - uint8_t detectCard[] = {0x00, 0x04, 0x02, 0x26, 0x07}; - + static uint16_t counter=0; + + rxBufPos = 0; + rxMsgComplete = false; + nfcWrite(detectCard, 5); + wait(0.2); + + if(blub == 0x80) { + led3 = true; + led4 = false; + printf("tag deteced UID (cnt %u):", counter++); + for(int pos=7;pos>=0;pos--) + { + printf("%02x", rxData[pos]); + } + printf("\r\n"); + } + else + { + led4 = true; + led3 = false; + printf("no tag (%02x)\r\n", blub); + } return(returnValue); } @@ -57,8 +78,31 @@ void CR95HF::rxCallbackNFC() { + uint8_t character; + while(nfcDevice.readable()) { - printf("%c", nfcDevice.getc()); - led3 = !led3; + character = nfcDevice.getc(); + + if(rxBufPos == 0) { + blub = character; + } + else if(rxBufPos == 1) { + len = character; + } + else if(rxBufPos == 2) { + + } + else if(rxBufPos == 3) { + + } + else { + rxData[rxBufPos-4] = character; + } + rxBufPos++; + + if(rxBufPos >= len) { + rxMsgComplete = true; + } + } -} \ No newline at end of file +}