CR95F X-Nucleo NFC03A1 Shield STM
Dependents: Nucleo_NFC03A1_Demo
CR95HF.cpp@1:549e63ac990c, 2018-08-30 (annotated)
- Committer:
- duchonic
- Date:
- Thu Aug 30 11:43:43 2018 +0000
- Revision:
- 1:549e63ac990c
- Parent:
- 0:57769c77d24e
- Child:
- 2:c7006765c441
working version
Who changed what in which revision?
User | Revision | Line number | New 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 | |
duchonic | 0:57769c77d24e | 35 | |
duchonic | 0:57769c77d24e | 36 | return(0); |
duchonic | 0:57769c77d24e | 37 | } |
duchonic | 0:57769c77d24e | 38 | |
duchonic | 1:549e63ac990c | 39 | uint8_t CR95HF::ConfigManagerTagHunting() |
duchonic | 0:57769c77d24e | 40 | { |
duchonic | 0:57769c77d24e | 41 | uint8_t returnValue = false; |
duchonic | 0:57769c77d24e | 42 | |
duchonic | 1:549e63ac990c | 43 | uint8_t detectCard[] = {0x00, 0x04, 0x02, 0x26, 0x07}; |
duchonic | 0:57769c77d24e | 44 | |
duchonic | 1:549e63ac990c | 45 | nfcWrite(detectCard, 5); |
duchonic | 0:57769c77d24e | 46 | |
duchonic | 0:57769c77d24e | 47 | return(returnValue); |
duchonic | 0:57769c77d24e | 48 | } |
duchonic | 0:57769c77d24e | 49 | |
duchonic | 0:57769c77d24e | 50 | /** private functions */ |
duchonic | 0:57769c77d24e | 51 | |
duchonic | 1:549e63ac990c | 52 | void CR95HF::nfcWrite(uint8_t cmd[], uint8_t len) |
duchonic | 0:57769c77d24e | 53 | { |
duchonic | 1:549e63ac990c | 54 | for(int pos=0; pos<len;pos++) |
duchonic | 1:549e63ac990c | 55 | { |
duchonic | 1:549e63ac990c | 56 | nfcDevice.putc(cmd[pos]); |
duchonic | 1:549e63ac990c | 57 | } |
duchonic | 1:549e63ac990c | 58 | } |
duchonic | 1:549e63ac990c | 59 | |
duchonic | 1:549e63ac990c | 60 | void CR95HF::rxCallbackNFC() |
duchonic | 1:549e63ac990c | 61 | { |
duchonic | 1:549e63ac990c | 62 | uint8_t chr; |
duchonic | 1:549e63ac990c | 63 | while(nfcDevice.readable()) { |
duchonic | 1:549e63ac990c | 64 | printf("%c", nfcDevice.getc()); |
duchonic | 1:549e63ac990c | 65 | led3 = !led3; |
duchonic | 1:549e63ac990c | 66 | } |
duchonic | 0:57769c77d24e | 67 | } |