CR95F X-Nucleo NFC03A1 Shield STM

Dependents:   Nucleo_NFC03A1_Demo

Committer:
duchonic
Date:
Fri Aug 31 06:33:12 2018 +0000
Revision:
2:c7006765c441
Parent:
1:549e63ac990c
Child:
3:12c871b2412d
documentation added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
duchonic 0:57769c77d24e 1 #include <CR95HF.h>
duchonic 0:57769c77d24e 2 #include "main.h"
duchonic 0:57769c77d24e 3
duchonic 0:57769c77d24e 4 DigitalOut InterfacePin(D9);
duchonic 0:57769c77d24e 5
duchonic 1:549e63ac990c 6 DigitalOut led1(D7);
duchonic 1:549e63ac990c 7 DigitalOut led2(D6);
duchonic 1:549e63ac990c 8 DigitalOut led3(D5);
duchonic 1:549e63ac990c 9 DigitalOut led4(D4);
duchonic 1:549e63ac990c 10
duchonic 1:549e63ac990c 11 CR95HF::CR95HF(PinName tx, PinName rx) : nfcDevice(tx,rx)
duchonic 0:57769c77d24e 12 {
duchonic 0:57769c77d24e 13 InterfacePin = false;
duchonic 0:57769c77d24e 14 }
duchonic 0:57769c77d24e 15
duchonic 0:57769c77d24e 16 CR95HF::~CR95HF() {};
duchonic 0:57769c77d24e 17
duchonic 1:549e63ac990c 18 uint8_t CR95HF::Init()
duchonic 0:57769c77d24e 19 {
duchonic 1:549e63ac990c 20 uint8_t commandInfo[] = {0x01, 0x00};
duchonic 1:549e63ac990c 21 uint8_t commandSetProtocoll[] = {0x02, 0x01, 0x02, 0x00};
duchonic 0:57769c77d24e 22
duchonic 0:57769c77d24e 23 printf("CR95HF_Init\r\n");
duchonic 0:57769c77d24e 24
duchonic 1:549e63ac990c 25 nfcDevice.baud(57600);
duchonic 0:57769c77d24e 26
duchonic 1:549e63ac990c 27 nfcDevice.attach(this, &CR95HF::rxCallbackNFC);
duchonic 0:57769c77d24e 28
duchonic 1:549e63ac990c 29 wait(1);
duchonic 1:549e63ac990c 30 nfcWrite(commandInfo, 2);
duchonic 1:549e63ac990c 31 wait(1);
duchonic 1:549e63ac990c 32 nfcWrite(commandSetProtocoll, 4);
duchonic 0:57769c77d24e 33
duchonic 0:57769c77d24e 34 return(0);
duchonic 0:57769c77d24e 35 }
duchonic 0:57769c77d24e 36
duchonic 1:549e63ac990c 37 uint8_t CR95HF::ConfigManagerTagHunting()
duchonic 0:57769c77d24e 38 {
duchonic 0:57769c77d24e 39 uint8_t returnValue = false;
duchonic 0:57769c77d24e 40
duchonic 1:549e63ac990c 41 uint8_t detectCard[] = {0x00, 0x04, 0x02, 0x26, 0x07};
duchonic 0:57769c77d24e 42
duchonic 1:549e63ac990c 43 nfcWrite(detectCard, 5);
duchonic 0:57769c77d24e 44
duchonic 0:57769c77d24e 45 return(returnValue);
duchonic 0:57769c77d24e 46 }
duchonic 0:57769c77d24e 47
duchonic 0:57769c77d24e 48 /** private functions */
duchonic 0:57769c77d24e 49
duchonic 1:549e63ac990c 50 void CR95HF::nfcWrite(uint8_t cmd[], uint8_t len)
duchonic 0:57769c77d24e 51 {
duchonic 1:549e63ac990c 52 for(int pos=0; pos<len;pos++)
duchonic 1:549e63ac990c 53 {
duchonic 1:549e63ac990c 54 nfcDevice.putc(cmd[pos]);
duchonic 1:549e63ac990c 55 }
duchonic 1:549e63ac990c 56 }
duchonic 1:549e63ac990c 57
duchonic 1:549e63ac990c 58 void CR95HF::rxCallbackNFC()
duchonic 1:549e63ac990c 59 {
duchonic 1:549e63ac990c 60 while(nfcDevice.readable()) {
duchonic 1:549e63ac990c 61 printf("%c", nfcDevice.getc());
duchonic 1:549e63ac990c 62 led3 = !led3;
duchonic 1:549e63ac990c 63 }
duchonic 0:57769c77d24e 64 }