interrupt handling

Dependencies:  

Committer:
soumi_ghsoh
Date:
Fri Apr 10 23:14:55 2015 +0000
Revision:
11:d5e8f47880f1
Parent:
10:98a58968dc7d
Child:
13:16a5b43ac874
pollNFC(), findNFC()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rwclough 1:1eb96189824d 1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
rwclough 2:bd5afc5aa139 2 Filename: main.cpp
rwclough 1:1eb96189824d 3 Description: Interface nRF51-DK eval board to TRF7970 eval board
rwclough 1:1eb96189824d 4 to test the suitability of the TRF7970 NFC chip
rwclough 1:1eb96189824d 5 for use in Gymtrack products.
rwclough 1:1eb96189824d 6 The nRF51-DK board has an nRF51422 MCU.
rwclough 1:1eb96189824d 7 Copyright (C) 2015 Gymtrack, Inc.
rwclough 1:1eb96189824d 8 Author: Ron Clough
rwclough 1:1eb96189824d 9 Date: 2015-02-26
rwclough 1:1eb96189824d 10
rwclough 1:1eb96189824d 11 Changes:
rwclough 1:1eb96189824d 12 Rev Date Who Details
rwclough 1:1eb96189824d 13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rwclough 1:1eb96189824d 14 0.0 2015-02-26 RWC Original version.
rwclough 1:1eb96189824d 15
rwclough 1:1eb96189824d 16 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
rwclough 0:5622c60e9d3a 17
rwclough 1:1eb96189824d 18 #include "mbed.h"
soumi_ghsoh 5:93c612f43ec2 19
soumi_ghsoh 5:93c612f43ec2 20 //#include "NFC_7970.h"
rwclough 1:1eb96189824d 21 #include "readerComm.h"
soumi_ghsoh 9:9266e0109d26 22 #include "BLEDevice.h"
soumi_ghsoh 9:9266e0109d26 23 #include "HeartRateService.h"
soumi_ghsoh 9:9266e0109d26 24 #include "DeviceInformationService.h"
rwclough 1:1eb96189824d 25 SPI spi(p25, p28, p29); // MOSI, MISO, SCLK
soumi_ghsoh 5:93c612f43ec2 26 // Slave Select (SS)
rwclough 1:1eb96189824d 27 Serial pc(USBTX, USBRX); // Serial communication over USB with PC
rwclough 3:eaae5433ab45 28 DigitalOut heartbeatLED(LED4); // "Heartbeat" LED
rwclough 3:eaae5433ab45 29 DigitalOut debug2LED(LED2); // "Debug2" LED
rwclough 3:eaae5433ab45 30 DigitalOut ISO15693LED(LED3); // "Detected ISO15693 tag" LED
rwclough 3:eaae5433ab45 31 DigitalOut debug1LED(LED1); // "Debug1" LED
soumi_ghsoh 10:98a58968dc7d 32 extern DigitalOut EN; // Control EN pin on TRF7970
soumi_ghsoh 10:98a58968dc7d 33 extern DigitalOut EN2; // Control EN2 pin on TRF7970
soumi_ghsoh 10:98a58968dc7d 34 extern DigitalOut CS;
soumi_ghsoh 9:9266e0109d26 35
soumi_ghsoh 7:96baf1b2fd07 36 //DigitalInOut ook_ask(p6); // Control ASK/OOK pin on TRF7970
soumi_ghsoh 7:96baf1b2fd07 37 //DigitalOut mod(p5); // Control MOD pin on TRF7970
soumi_ghsoh 7:96baf1b2fd07 38 InterruptIn readerInt(p7);
rwclough 3:eaae5433ab45 39 DigitalOut testPin(p1);
soumi_ghsoh 9:9266e0109d26 40 BLEDevice ble;
soumi_ghsoh 11:d5e8f47880f1 41 extern uint8_t buf[300];
soumi_ghsoh 7:96baf1b2fd07 42 uint8_t noBytes=0;
soumi_ghsoh 9:9266e0109d26 43 extern uint8_t turnRFOn[2];
soumi_ghsoh 9:9266e0109d26 44 extern uint8_t testcommand[2];
soumi_ghsoh 11:d5e8f47880f1 45 extern uint8_t found;
soumi_ghsoh 11:d5e8f47880f1 46
soumi_ghsoh 7:96baf1b2fd07 47 bool tagFound=0;
soumi_ghsoh 11:d5e8f47880f1 48 //uint8_t WAIT=0;
soumi_ghsoh 11:d5e8f47880f1 49
rwclough 2:bd5afc5aa139 50 int main()
soumi_ghsoh 9:9266e0109d26 51 {testPin=0;
soumi_ghsoh 6:3c510c297e2f 52 pc.baud(115200);
soumi_ghsoh 9:9266e0109d26 53 //=============================================================ble test
soumi_ghsoh 9:9266e0109d26 54 ble.init();
soumi_ghsoh 9:9266e0109d26 55 // ble.onDisconnection(disconnectionCallback);
soumi_ghsoh 9:9266e0109d26 56 //
soumi_ghsoh 9:9266e0109d26 57 // /* Setup advertising. */
soumi_ghsoh 9:9266e0109d26 58 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
soumi_ghsoh 9:9266e0109d26 59 // // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
soumi_ghsoh 9:9266e0109d26 60 ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
soumi_ghsoh 9:9266e0109d26 61 // // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
soumi_ghsoh 9:9266e0109d26 62 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
soumi_ghsoh 9:9266e0109d26 63 ble.setAdvertisingInterval(1000);
soumi_ghsoh 9:9266e0109d26 64 ble.startAdvertising();
soumi_ghsoh 9:9266e0109d26 65 //===============================================================*/
soumi_ghsoh 9:9266e0109d26 66
soumi_ghsoh 7:96baf1b2fd07 67 readerInt.rise(&handlerNFC);
soumi_ghsoh 10:98a58968dc7d 68 CS=1;
soumi_ghsoh 6:3c510c297e2f 69 SpiInit(); //spi=1Mhz
soumi_ghsoh 11:d5e8f47880f1 70 PowerUpNFC();
soumi_ghsoh 6:3c510c297e2f 71 NFCInit();
soumi_ghsoh 10:98a58968dc7d 72 RegisterReInitNFC();
soumi_ghsoh 10:98a58968dc7d 73 RegistersReadNFC();
soumi_ghsoh 11:d5e8f47880f1 74 PowerDownNFC(); //SleepNFC() //StandByNFC()
soumi_ghsoh 11:d5e8f47880f1 75 //SleepNFC();
soumi_ghsoh 9:9266e0109d26 76
soumi_ghsoh 6:3c510c297e2f 77 while(1)
soumi_ghsoh 11:d5e8f47880f1 78 {
soumi_ghsoh 11:d5e8f47880f1 79 tagFound=PollNFC();
soumi_ghsoh 11:d5e8f47880f1 80
soumi_ghsoh 11:d5e8f47880f1 81 if(tagFound==1)
soumi_ghsoh 11:d5e8f47880f1 82 {//printf("read single block:");
soumi_ghsoh 11:d5e8f47880f1 83 for(uint8_t i=0; i<noBytes; i++)
soumi_ghsoh 11:d5e8f47880f1 84 printf("%X ", buf[i]);
soumi_ghsoh 11:d5e8f47880f1 85 printf("\r\n");
soumi_ghsoh 11:d5e8f47880f1 86 printf("tag found \r\n");
soumi_ghsoh 11:d5e8f47880f1 87 break;
soumi_ghsoh 11:d5e8f47880f1 88 }
soumi_ghsoh 11:d5e8f47880f1 89 else wait(1);
soumi_ghsoh 11:d5e8f47880f1 90 }
soumi_ghsoh 11:d5e8f47880f1 91
soumi_ghsoh 7:96baf1b2fd07 92 }
soumi_ghsoh 9:9266e0109d26 93
soumi_ghsoh 5:93c612f43ec2 94