interrupt handling

Dependencies:  

main.cpp

Committer:
rwclough
Date:
2015-03-05
Revision:
2:bd5afc5aa139
Parent:
1:1eb96189824d
Child:
3:eaae5433ab45

File content as of revision 2:bd5afc5aa139:

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    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.
                    The nRF51-DK board has an nRF51422 MCU.
    Copyright (C)   2015 Gymtrack, Inc.
    Author:         Ron Clough
    Date:           2015-02-26
    
    Changes:
    Rev     Date        Who     Details
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    0.0     2015-02-26  RWC     Original version.
    
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include    "mbed.h"
#include    "main.h"
#include    "readerComm.h"
#include    "interruptStuff.h"

SPI         spi(p25, p28, p29); // MOSI, MISO, SCLK
DigitalOut  CS(p19);            // Slave Select (SS)
Serial      pc(USBTX, USBRX);   // Serial communication over USB with PC
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

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)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//  blinkHeartbeatLED()
//  Description:    Toogle the heartbeat LED.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
{
    heartbeatLED = !heartbeatLED;
}   // End of blinkHeartbeatLED()

int main()
{
    // Power up sequence
    CS = 0; enable2 = 0; enable = 0;
    wait_ms(2);
    CS = 1;
    wait_ms(3);
    enable2 = 1;
    wait_ms(1);
    enable = 1;
    
    mod = 0;
    
    //  Setup serial communication
    pc.baud(115200);
    printf("\r\nInitialization: ");
    
    //  Setup heartbeat LED
    heartbeatLED = LED_OFF;
    ISO15693LED = LED_OFF;
    Ticker  heartbeat;
    heartbeat.attach(blinkHeartbeatLED, 1);
    printf("Heartbeat, ");
    
    //  Setup the SPI interface
    spi.format(8, 3);       // 8 bit data, mode = 3
    spi.frequency(1000000); // SCLK = 1 MHz
    printf("SPI, ");
    
    //  Set On-Off Keying modulation
    ook_ask = 1;
    printf("OOK, ");
    
    //  Apply initial settings to the TRF7970
    initialSettings();
    printf("Initialized, ");
    
    //  Setup interrupt from TRF7970
    setupIrq();
    printf("IRQ setup and disabled, ");
    
    printf("finished init.\r\n\r\n");
    
    iso15693FindTag();
    
}   // End of main()