interrupt handling

Dependencies:  

Revision:
2:bd5afc5aa139
Parent:
1:1eb96189824d
Child:
3:eaae5433ab45
--- a/main.cpp	Mon Mar 02 19:50:31 2015 +0000
+++ b/main.cpp	Thu Mar 05 20:16:40 2015 +0000
@@ -1,5 +1,5 @@
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-    Filename:       main.c
+    Filename:       main.cpp
     Description:    Interface nRF51-DK eval board to TRF7970 eval board 
                     to test the suitability of the TRF7970 NFC chip 
                     for use in Gymtrack products.
@@ -18,39 +18,45 @@
 #include    "mbed.h"
 #include    "main.h"
 #include    "readerComm.h"
+#include    "interruptStuff.h"
 
 SPI         spi(p25, p28, p29); // MOSI, MISO, SCLK
-DigitalOut  CS(p11);            // Slave Select (SS)
+DigitalOut  CS(p19);            // Slave Select (SS)
 Serial      pc(USBTX, USBRX);   // Serial communication over USB with PC
-DigitalOut  heartbeatLED(LED1); // Heartbeat LED
-InterruptIn readerInt(p7);      // Interrupt from TRF7970
+DigitalOut  heartbeatLED(LED1); // "Heartbeat" LED
+DigitalOut  ISO15693LED(LED2);  // "Detected ISO15693 tag" LED
 DigitalOut  ook_ask(p6);        // Control ASK/OOK pin on TRF7970
 DigitalOut  mod(p5);            // Control MOD pin on TRF7970
 DigitalOut  enable(p4);         // Control EN pin on TRF7970
 DigitalOut  enable2(p3);        // Control EN2 pin on TRF7970
 
-int         buffer[2];
+uint8_t     buffer[2];
+int8_t      rxtxState = 1;      // Transmit/Receive byte count
+uint8_t     buf[300];
+uint8_t     irqRegister = 0x01; // Interrupt register
+uint8_t     irqFlag = 0x00;
+uint8_t     rxErrorFlag = 0x00;
+uint8_t     readerMode = 0x00;  // Determines how interrupts will be handled
+int16_t     nfc_state;
+uint8_t     nfc_protocol;
+uint8_t     active;
+uint8_t     tagFlag;
 
-void blinkHeartbeatLED(void) {
+void blinkHeartbeatLED(void)
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 //  blinkHeartbeatLED()
 //  Description:    Toogle the heartbeat LED.
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+{
     heartbeatLED = !heartbeatLED;
 }   // End of blinkHeartbeatLED()
 
-void intHandler() {
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  intHandler()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-    printf("Got Interrupt!\r\n");
-}   // End of intHandler()
-
-int main() {
+int main()
+{
     // Power up sequence
     CS = 0; enable2 = 0; enable = 0;
     wait_ms(2);
-    CS = DESELECT;
+    CS = 1;
     wait_ms(3);
     enable2 = 1;
     wait_ms(1);
@@ -60,10 +66,11 @@
     
     //  Setup serial communication
     pc.baud(115200);
-    printf("Initialization: ");
+    printf("\r\nInitialization: ");
     
     //  Setup heartbeat LED
     heartbeatLED = LED_OFF;
+    ISO15693LED = LED_OFF;
     Ticker  heartbeat;
     heartbeat.attach(blinkHeartbeatLED, 1);
     printf("Heartbeat, ");
@@ -77,38 +84,16 @@
     ook_ask = 1;
     printf("OOK, ");
     
-    //  Establish communication with the TRF7970
-    firstComm();
-    printf("Communication established, ");
+    //  Apply initial settings to the TRF7970
+    initialSettings();
+    printf("Initialized, ");
     
     //  Setup interrupt from TRF7970
-    readerInt.rise(&intHandler);    // Interrupt on rising edge, call intHandler()
-    printf("Interrupt enabled, ");
-    
-    printf("finished initialization.\r\n");
-    
-    //  Begin Test
-    buffer[0] = RAM_0;      // Address 0x12
-    buffer[1] = 0x55;
-    writeSingle(buffer, 2);
-    wait_ms(100);
-    readSingle(buffer, 1);
-    printf("Reg[0]: 0x%X\r\n", buffer[0]);
-    printf("Reg[1]: 0x%X\r\n", buffer[1]);
+    setupIrq();
+    printf("IRQ setup and disabled, ");
     
-    buffer[0] = RAM_0;      // Address 0x12
-    buffer[1] = 0xAA;
-    writeSingle(buffer, 2);
-    wait_ms(100);
-    readSingle(buffer, 1);
-    printf("Reg[0]: 0x%X\r\n", buffer[0]);
-    printf("Reg[1]: 0x%X\r\n", buffer[1]);
-    //  End Test
+    printf("finished init.\r\n\r\n");
     
-    wait(1);
+    iso15693FindTag();
     
-    while(TRUE) {
-        printf("Got here . . . Yeah!\r\n");
-        wait_ms(1000);
-    }
 }   // End of main()