interrupt handling
main.cpp@9:9266e0109d26, 2015-04-08 (annotated)
- Committer:
- soumi_ghsoh
- Date:
- Wed Apr 08 20:48:05 2015 +0000
- Revision:
- 9:9266e0109d26
- Parent:
- 7:96baf1b2fd07
- Child:
- 10:98a58968dc7d
power modes sg
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:9266e0109d26 | 32 | |
soumi_ghsoh | 9:9266e0109d26 | 33 | |
soumi_ghsoh | 7:96baf1b2fd07 | 34 | //DigitalInOut ook_ask(p6); // Control ASK/OOK pin on TRF7970 |
soumi_ghsoh | 7:96baf1b2fd07 | 35 | //DigitalOut mod(p5); // Control MOD pin on TRF7970 |
soumi_ghsoh | 7:96baf1b2fd07 | 36 | InterruptIn readerInt(p7); |
rwclough | 3:eaae5433ab45 | 37 | DigitalOut testPin(p1); |
soumi_ghsoh | 9:9266e0109d26 | 38 | BLEDevice ble; |
rwclough | 2:bd5afc5aa139 | 39 | uint8_t buf[300]; |
soumi_ghsoh | 7:96baf1b2fd07 | 40 | uint8_t noBytes=0; |
soumi_ghsoh | 9:9266e0109d26 | 41 | extern uint8_t turnRFOn[2]; |
soumi_ghsoh | 9:9266e0109d26 | 42 | extern uint8_t testcommand[2]; |
soumi_ghsoh | 7:96baf1b2fd07 | 43 | uint8_t found=0; |
soumi_ghsoh | 7:96baf1b2fd07 | 44 | bool tagFound=0; |
rwclough | 2:bd5afc5aa139 | 45 | int main() |
soumi_ghsoh | 9:9266e0109d26 | 46 | {testPin=0; |
soumi_ghsoh | 6:3c510c297e2f | 47 | pc.baud(115200); |
soumi_ghsoh | 9:9266e0109d26 | 48 | |
soumi_ghsoh | 9:9266e0109d26 | 49 | //=============================================================ble test |
soumi_ghsoh | 9:9266e0109d26 | 50 | ble.init(); |
soumi_ghsoh | 9:9266e0109d26 | 51 | // ble.onDisconnection(disconnectionCallback); |
soumi_ghsoh | 9:9266e0109d26 | 52 | // |
soumi_ghsoh | 9:9266e0109d26 | 53 | // /* Setup advertising. */ |
soumi_ghsoh | 9:9266e0109d26 | 54 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
soumi_ghsoh | 9:9266e0109d26 | 55 | // // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); |
soumi_ghsoh | 9:9266e0109d26 | 56 | ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); |
soumi_ghsoh | 9:9266e0109d26 | 57 | // // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
soumi_ghsoh | 9:9266e0109d26 | 58 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
soumi_ghsoh | 9:9266e0109d26 | 59 | ble.setAdvertisingInterval(1000); |
soumi_ghsoh | 9:9266e0109d26 | 60 | ble.startAdvertising(); |
soumi_ghsoh | 9:9266e0109d26 | 61 | //===============================================================*/ |
soumi_ghsoh | 9:9266e0109d26 | 62 | |
soumi_ghsoh | 7:96baf1b2fd07 | 63 | readerInt.rise(&handlerNFC); |
soumi_ghsoh | 6:3c510c297e2f | 64 | SpiInit(); //spi=1Mhz |
soumi_ghsoh | 9:9266e0109d26 | 65 | PowerUpNFC2(); |
soumi_ghsoh | 9:9266e0109d26 | 66 | |
soumi_ghsoh | 6:3c510c297e2f | 67 | NFCInit(); |
soumi_ghsoh | 9:9266e0109d26 | 68 | //wait_ms(1); |
soumi_ghsoh | 9:9266e0109d26 | 69 | //RegisterReInitNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 70 | //RegistersReadNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 71 | //wait_ms(10); |
soumi_ghsoh | 9:9266e0109d26 | 72 | //PowerDownNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 73 | //wait(10); |
soumi_ghsoh | 9:9266e0109d26 | 74 | // |
soumi_ghsoh | 9:9266e0109d26 | 75 | //PowerUpNFC2(); |
soumi_ghsoh | 9:9266e0109d26 | 76 | //NFCInit(); |
soumi_ghsoh | 9:9266e0109d26 | 77 | //// |
soumi_ghsoh | 9:9266e0109d26 | 78 | //wait_ms(1); |
soumi_ghsoh | 9:9266e0109d26 | 79 | //RegisterReInitNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 80 | |
soumi_ghsoh | 9:9266e0109d26 | 81 | //RegistersReadNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 82 | |
soumi_ghsoh | 9:9266e0109d26 | 83 | |
soumi_ghsoh | 9:9266e0109d26 | 84 | |
soumi_ghsoh | 9:9266e0109d26 | 85 | |
soumi_ghsoh | 9:9266e0109d26 | 86 | //wait_ms(10); |
soumi_ghsoh | 9:9266e0109d26 | 87 | //PowerUpNFC(); |
soumi_ghsoh | 6:3c510c297e2f | 88 | while(1) |
soumi_ghsoh | 9:9266e0109d26 | 89 | {PowerUpNFC2(); |
soumi_ghsoh | 9:9266e0109d26 | 90 | NFCInit(); |
soumi_ghsoh | 9:9266e0109d26 | 91 | //wait_ms(1); |
soumi_ghsoh | 9:9266e0109d26 | 92 | //RegisterReInitNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 93 | //RegistersReadNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 94 | //turnRFOn[0] = CHIP_STATUS_CONTROL; |
soumi_ghsoh | 9:9266e0109d26 | 95 | //turnRFOn[1] = CHIP_STATUS_CONTROL; |
soumi_ghsoh | 9:9266e0109d26 | 96 | //// |
soumi_ghsoh | 9:9266e0109d26 | 97 | //turnRFOn[1] &= 0x3F; |
soumi_ghsoh | 9:9266e0109d26 | 98 | //turnRFOn[1] |= 0x20; |
soumi_ghsoh | 9:9266e0109d26 | 99 | //trf797xWriteSingle(turnRFOn, 2); |
soumi_ghsoh | 9:9266e0109d26 | 100 | //////wait_ms(2); |
soumi_ghsoh | 9:9266e0109d26 | 101 | //// |
soumi_ghsoh | 9:9266e0109d26 | 102 | //testcommand[0] = ISO_CONTROL; |
soumi_ghsoh | 9:9266e0109d26 | 103 | //testcommand[1] = 0x02; // 6.78 MHz, OOK 100% |
soumi_ghsoh | 9:9266e0109d26 | 104 | //trf797xWriteSingle(testcommand, 2); |
soumi_ghsoh | 9:9266e0109d26 | 105 | //RegisterReInitNFC(); |
soumi_ghsoh | 7:96baf1b2fd07 | 106 | MemReadReqNFC(); |
soumi_ghsoh | 7:96baf1b2fd07 | 107 | if(found==1) |
soumi_ghsoh | 7:96baf1b2fd07 | 108 | { |
soumi_ghsoh | 7:96baf1b2fd07 | 109 | ReadNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 110 | PowerDownNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 111 | //printf("read single block:"); |
soumi_ghsoh | 7:96baf1b2fd07 | 112 | for(uint8_t i=0; i<noBytes; i++) |
soumi_ghsoh | 7:96baf1b2fd07 | 113 | printf("%X ", buf[i]); |
soumi_ghsoh | 7:96baf1b2fd07 | 114 | printf("\r\n"); |
soumi_ghsoh | 7:96baf1b2fd07 | 115 | found=0; |
soumi_ghsoh | 7:96baf1b2fd07 | 116 | } |
soumi_ghsoh | 7:96baf1b2fd07 | 117 | else |
soumi_ghsoh | 7:96baf1b2fd07 | 118 | {printf("tnf1 \r\n"); |
soumi_ghsoh | 7:96baf1b2fd07 | 119 | } |
soumi_ghsoh | 9:9266e0109d26 | 120 | //InventoryReqNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 121 | //if(found==1) |
soumi_ghsoh | 9:9266e0109d26 | 122 | //{ |
soumi_ghsoh | 9:9266e0109d26 | 123 | //ReadNFC(); |
soumi_ghsoh | 9:9266e0109d26 | 124 | //printf("tag id:"); |
soumi_ghsoh | 9:9266e0109d26 | 125 | //for(uint8_t i=0; i<noBytes; i++) |
soumi_ghsoh | 9:9266e0109d26 | 126 | //printf("%X ", buf[i]); |
soumi_ghsoh | 9:9266e0109d26 | 127 | //printf("\r\n"); |
soumi_ghsoh | 9:9266e0109d26 | 128 | //found=0; |
soumi_ghsoh | 9:9266e0109d26 | 129 | //} |
soumi_ghsoh | 9:9266e0109d26 | 130 | //else |
soumi_ghsoh | 9:9266e0109d26 | 131 | //{printf("tnf2 \r\n"); |
soumi_ghsoh | 9:9266e0109d26 | 132 | //} |
soumi_ghsoh | 9:9266e0109d26 | 133 | wait(1); |
soumi_ghsoh | 7:96baf1b2fd07 | 134 | } |
soumi_ghsoh | 9:9266e0109d26 | 135 | |
soumi_ghsoh | 6:3c510c297e2f | 136 | } |
soumi_ghsoh | 5:93c612f43ec2 | 137 | |
soumi_ghsoh | 5:93c612f43ec2 | 138 | |
soumi_ghsoh | 5:93c612f43ec2 | 139 | |
soumi_ghsoh | 5:93c612f43ec2 | 140 | |
soumi_ghsoh | 5:93c612f43ec2 | 141 | |
soumi_ghsoh | 5:93c612f43ec2 | 142 | |
soumi_ghsoh | 5:93c612f43ec2 | 143 | |
soumi_ghsoh | 5:93c612f43ec2 | 144 | |
soumi_ghsoh | 5:93c612f43ec2 | 145 |