interrupt handling

Dependencies:  

Committer:
soumi_ghsoh
Date:
Thu Apr 09 22:09:35 2015 +0000
Revision:
10:98a58968dc7d
Parent:
9:9266e0109d26
Child:
11:d5e8f47880f1
sg apr 9/15

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;
rwclough 2:bd5afc5aa139 41 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 10:98a58968dc7d 45 uint8_t found=4;
soumi_ghsoh 7:96baf1b2fd07 46 bool tagFound=0;
rwclough 2:bd5afc5aa139 47 int main()
soumi_ghsoh 9:9266e0109d26 48 {testPin=0;
soumi_ghsoh 6:3c510c297e2f 49 pc.baud(115200);
soumi_ghsoh 9:9266e0109d26 50 //=============================================================ble test
soumi_ghsoh 9:9266e0109d26 51 ble.init();
soumi_ghsoh 9:9266e0109d26 52 // ble.onDisconnection(disconnectionCallback);
soumi_ghsoh 9:9266e0109d26 53 //
soumi_ghsoh 9:9266e0109d26 54 // /* Setup advertising. */
soumi_ghsoh 9:9266e0109d26 55 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
soumi_ghsoh 9:9266e0109d26 56 // // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
soumi_ghsoh 9:9266e0109d26 57 ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
soumi_ghsoh 9:9266e0109d26 58 // // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
soumi_ghsoh 9:9266e0109d26 59 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
soumi_ghsoh 9:9266e0109d26 60 ble.setAdvertisingInterval(1000);
soumi_ghsoh 9:9266e0109d26 61 ble.startAdvertising();
soumi_ghsoh 9:9266e0109d26 62 //===============================================================*/
soumi_ghsoh 9:9266e0109d26 63
soumi_ghsoh 7:96baf1b2fd07 64 readerInt.rise(&handlerNFC);
soumi_ghsoh 10:98a58968dc7d 65 CS=1;
soumi_ghsoh 10:98a58968dc7d 66 //NFC_SLEEP;
soumi_ghsoh 10:98a58968dc7d 67 //NFC_SLEEP;
soumi_ghsoh 10:98a58968dc7d 68 EN2=1;
soumi_ghsoh 10:98a58968dc7d 69 //wait_ms(1);
soumi_ghsoh 6:3c510c297e2f 70 SpiInit(); //spi=1Mhz
soumi_ghsoh 10:98a58968dc7d 71 //PowerUpNFC();
soumi_ghsoh 10:98a58968dc7d 72 NFC_ON;
soumi_ghsoh 10:98a58968dc7d 73 //wait_ms(1);
soumi_ghsoh 9:9266e0109d26 74
soumi_ghsoh 6:3c510c297e2f 75 NFCInit();
soumi_ghsoh 10:98a58968dc7d 76 RegisterReInitNFC();
soumi_ghsoh 10:98a58968dc7d 77 RegistersReadNFC();
soumi_ghsoh 10:98a58968dc7d 78 //wait(1);
soumi_ghsoh 10:98a58968dc7d 79 NFC_OFF;
soumi_ghsoh 9:9266e0109d26 80
soumi_ghsoh 9:9266e0109d26 81
soumi_ghsoh 6:3c510c297e2f 82 while(1)
soumi_ghsoh 10:98a58968dc7d 83 { CS=1;
soumi_ghsoh 10:98a58968dc7d 84 NFC_ON;
soumi_ghsoh 10:98a58968dc7d 85 ////wait_ms(1);
soumi_ghsoh 10:98a58968dc7d 86 NFCInit();
soumi_ghsoh 10:98a58968dc7d 87 RegisterReInitNFC();
soumi_ghsoh 7:96baf1b2fd07 88 MemReadReqNFC();
soumi_ghsoh 7:96baf1b2fd07 89 if(found==1)
soumi_ghsoh 7:96baf1b2fd07 90 {
soumi_ghsoh 7:96baf1b2fd07 91 ReadNFC();
soumi_ghsoh 10:98a58968dc7d 92 wait_ms(1);
soumi_ghsoh 10:98a58968dc7d 93 NFC_OFF;
soumi_ghsoh 10:98a58968dc7d 94 //PowerDownNFC();
soumi_ghsoh 9:9266e0109d26 95 //printf("read single block:");
soumi_ghsoh 7:96baf1b2fd07 96 for(uint8_t i=0; i<noBytes; i++)
soumi_ghsoh 7:96baf1b2fd07 97 printf("%X ", buf[i]);
soumi_ghsoh 7:96baf1b2fd07 98 printf("\r\n");
soumi_ghsoh 10:98a58968dc7d 99 found=4;
soumi_ghsoh 7:96baf1b2fd07 100 }
soumi_ghsoh 10:98a58968dc7d 101 else if(found==3)
soumi_ghsoh 7:96baf1b2fd07 102 {printf("tnf1 \r\n");
soumi_ghsoh 10:98a58968dc7d 103 printf("%d ",found);
soumi_ghsoh 10:98a58968dc7d 104 found=4;
soumi_ghsoh 7:96baf1b2fd07 105 }
soumi_ghsoh 9:9266e0109d26 106 //InventoryReqNFC();
soumi_ghsoh 9:9266e0109d26 107 //if(found==1)
soumi_ghsoh 9:9266e0109d26 108 //{
soumi_ghsoh 9:9266e0109d26 109 //ReadNFC();
soumi_ghsoh 9:9266e0109d26 110 //printf("tag id:");
soumi_ghsoh 9:9266e0109d26 111 //for(uint8_t i=0; i<noBytes; i++)
soumi_ghsoh 9:9266e0109d26 112 //printf("%X ", buf[i]);
soumi_ghsoh 9:9266e0109d26 113 //printf("\r\n");
soumi_ghsoh 9:9266e0109d26 114 //found=0;
soumi_ghsoh 9:9266e0109d26 115 //}
soumi_ghsoh 9:9266e0109d26 116 //else
soumi_ghsoh 9:9266e0109d26 117 //{printf("tnf2 \r\n");
soumi_ghsoh 9:9266e0109d26 118 //}
soumi_ghsoh 9:9266e0109d26 119 wait(1);
soumi_ghsoh 7:96baf1b2fd07 120 }
soumi_ghsoh 9:9266e0109d26 121
soumi_ghsoh 6:3c510c297e2f 122 }
soumi_ghsoh 5:93c612f43ec2 123
soumi_ghsoh 5:93c612f43ec2 124
soumi_ghsoh 5:93c612f43ec2 125
soumi_ghsoh 5:93c612f43ec2 126
soumi_ghsoh 5:93c612f43ec2 127
soumi_ghsoh 5:93c612f43ec2 128
soumi_ghsoh 5:93c612f43ec2 129
soumi_ghsoh 5:93c612f43ec2 130
soumi_ghsoh 5:93c612f43ec2 131