interrupt handling

Dependencies:  

main.cpp

Committer:
rwclough
Date:
2015-03-02
Revision:
1:1eb96189824d
Parent:
0:5622c60e9d3a
Child:
2:bd5afc5aa139

File content as of revision 1:1eb96189824d:

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    Filename:       main.c
    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"

SPI         spi(p25, p28, p29); // MOSI, MISO, SCLK
DigitalOut  CS(p11);            // 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  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];

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() {
    // Power up sequence
    CS = 0; enable2 = 0; enable = 0;
    wait_ms(2);
    CS = DESELECT;
    wait_ms(3);
    enable2 = 1;
    wait_ms(1);
    enable = 1;
    
    mod = 0;
    
    //  Setup serial communication
    pc.baud(115200);
    printf("Initialization: ");
    
    //  Setup heartbeat LED
    heartbeatLED = 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, ");
    
    //  Establish communication with the TRF7970
    firstComm();
    printf("Communication established, ");
    
    //  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]);
    
    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
    
    wait(1);
    
    while(TRUE) {
        printf("Got here . . . Yeah!\r\n");
        wait_ms(1000);
    }
}   // End of main()