interrupt handling

Dependencies:  

Committer:
rwclough
Date:
Thu Mar 05 20:16:40 2015 +0000
Revision:
2:bd5afc5aa139
Parent:
1:1eb96189824d
Child:
3:eaae5433ab45
Correction to last commit: This program is NOT able to write/read TRF7970 registers! I don't know why not. ; According to my logic analyzer, 2 IRQs are generated. They are NOT recognized by this program. A simple test IRQ handler does recognize them.

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"
rwclough 1:1eb96189824d 19 #include "main.h"
rwclough 1:1eb96189824d 20 #include "readerComm.h"
rwclough 2:bd5afc5aa139 21 #include "interruptStuff.h"
rwclough 0:5622c60e9d3a 22
rwclough 1:1eb96189824d 23 SPI spi(p25, p28, p29); // MOSI, MISO, SCLK
rwclough 2:bd5afc5aa139 24 DigitalOut CS(p19); // Slave Select (SS)
rwclough 1:1eb96189824d 25 Serial pc(USBTX, USBRX); // Serial communication over USB with PC
rwclough 2:bd5afc5aa139 26 DigitalOut heartbeatLED(LED1); // "Heartbeat" LED
rwclough 2:bd5afc5aa139 27 DigitalOut ISO15693LED(LED2); // "Detected ISO15693 tag" LED
rwclough 1:1eb96189824d 28 DigitalOut ook_ask(p6); // Control ASK/OOK pin on TRF7970
rwclough 1:1eb96189824d 29 DigitalOut mod(p5); // Control MOD pin on TRF7970
rwclough 1:1eb96189824d 30 DigitalOut enable(p4); // Control EN pin on TRF7970
rwclough 1:1eb96189824d 31 DigitalOut enable2(p3); // Control EN2 pin on TRF7970
rwclough 0:5622c60e9d3a 32
rwclough 2:bd5afc5aa139 33 uint8_t buffer[2];
rwclough 2:bd5afc5aa139 34 int8_t rxtxState = 1; // Transmit/Receive byte count
rwclough 2:bd5afc5aa139 35 uint8_t buf[300];
rwclough 2:bd5afc5aa139 36 uint8_t irqRegister = 0x01; // Interrupt register
rwclough 2:bd5afc5aa139 37 uint8_t irqFlag = 0x00;
rwclough 2:bd5afc5aa139 38 uint8_t rxErrorFlag = 0x00;
rwclough 2:bd5afc5aa139 39 uint8_t readerMode = 0x00; // Determines how interrupts will be handled
rwclough 2:bd5afc5aa139 40 int16_t nfc_state;
rwclough 2:bd5afc5aa139 41 uint8_t nfc_protocol;
rwclough 2:bd5afc5aa139 42 uint8_t active;
rwclough 2:bd5afc5aa139 43 uint8_t tagFlag;
rwclough 0:5622c60e9d3a 44
rwclough 2:bd5afc5aa139 45 void blinkHeartbeatLED(void)
rwclough 1:1eb96189824d 46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
rwclough 1:1eb96189824d 47 // blinkHeartbeatLED()
rwclough 1:1eb96189824d 48 // Description: Toogle the heartbeat LED.
rwclough 1:1eb96189824d 49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
rwclough 2:bd5afc5aa139 50 {
rwclough 1:1eb96189824d 51 heartbeatLED = !heartbeatLED;
rwclough 1:1eb96189824d 52 } // End of blinkHeartbeatLED()
rwclough 0:5622c60e9d3a 53
rwclough 2:bd5afc5aa139 54 int main()
rwclough 2:bd5afc5aa139 55 {
rwclough 1:1eb96189824d 56 // Power up sequence
rwclough 1:1eb96189824d 57 CS = 0; enable2 = 0; enable = 0;
rwclough 1:1eb96189824d 58 wait_ms(2);
rwclough 2:bd5afc5aa139 59 CS = 1;
rwclough 1:1eb96189824d 60 wait_ms(3);
rwclough 1:1eb96189824d 61 enable2 = 1;
rwclough 1:1eb96189824d 62 wait_ms(1);
rwclough 1:1eb96189824d 63 enable = 1;
rwclough 1:1eb96189824d 64
rwclough 1:1eb96189824d 65 mod = 0;
rwclough 1:1eb96189824d 66
rwclough 1:1eb96189824d 67 // Setup serial communication
rwclough 0:5622c60e9d3a 68 pc.baud(115200);
rwclough 2:bd5afc5aa139 69 printf("\r\nInitialization: ");
rwclough 1:1eb96189824d 70
rwclough 1:1eb96189824d 71 // Setup heartbeat LED
rwclough 1:1eb96189824d 72 heartbeatLED = LED_OFF;
rwclough 2:bd5afc5aa139 73 ISO15693LED = LED_OFF;
rwclough 1:1eb96189824d 74 Ticker heartbeat;
rwclough 1:1eb96189824d 75 heartbeat.attach(blinkHeartbeatLED, 1);
rwclough 1:1eb96189824d 76 printf("Heartbeat, ");
rwclough 1:1eb96189824d 77
rwclough 1:1eb96189824d 78 // Setup the SPI interface
rwclough 1:1eb96189824d 79 spi.format(8, 3); // 8 bit data, mode = 3
rwclough 1:1eb96189824d 80 spi.frequency(1000000); // SCLK = 1 MHz
rwclough 1:1eb96189824d 81 printf("SPI, ");
rwclough 1:1eb96189824d 82
rwclough 1:1eb96189824d 83 // Set On-Off Keying modulation
rwclough 1:1eb96189824d 84 ook_ask = 1;
rwclough 1:1eb96189824d 85 printf("OOK, ");
rwclough 1:1eb96189824d 86
rwclough 2:bd5afc5aa139 87 // Apply initial settings to the TRF7970
rwclough 2:bd5afc5aa139 88 initialSettings();
rwclough 2:bd5afc5aa139 89 printf("Initialized, ");
rwclough 1:1eb96189824d 90
rwclough 1:1eb96189824d 91 // Setup interrupt from TRF7970
rwclough 2:bd5afc5aa139 92 setupIrq();
rwclough 2:bd5afc5aa139 93 printf("IRQ setup and disabled, ");
rwclough 1:1eb96189824d 94
rwclough 2:bd5afc5aa139 95 printf("finished init.\r\n\r\n");
rwclough 1:1eb96189824d 96
rwclough 2:bd5afc5aa139 97 iso15693FindTag();
rwclough 1:1eb96189824d 98
rwclough 1:1eb96189824d 99 } // End of main()