interrupt handling
main.cpp@1:1eb96189824d, 2015-03-02 (annotated)
- Committer:
- rwclough
- Date:
- Mon Mar 02 19:50:31 2015 +0000
- Revision:
- 1:1eb96189824d
- Parent:
- 0:5622c60e9d3a
- Child:
- 2:bd5afc5aa139
The SPI interface between nRF51-DK and TRF7970 eval board works such that RAM_0 register can be written and read. Test values are 0xAA and 0x55.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rwclough | 1:1eb96189824d | 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
rwclough | 1:1eb96189824d | 2 | Filename: main.c |
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 | 0:5622c60e9d3a | 21 | |
rwclough | 1:1eb96189824d | 22 | SPI spi(p25, p28, p29); // MOSI, MISO, SCLK |
rwclough | 1:1eb96189824d | 23 | DigitalOut CS(p11); // Slave Select (SS) |
rwclough | 1:1eb96189824d | 24 | Serial pc(USBTX, USBRX); // Serial communication over USB with PC |
rwclough | 1:1eb96189824d | 25 | DigitalOut heartbeatLED(LED1); // Heartbeat LED |
rwclough | 1:1eb96189824d | 26 | InterruptIn readerInt(p7); // Interrupt from TRF7970 |
rwclough | 1:1eb96189824d | 27 | DigitalOut ook_ask(p6); // Control ASK/OOK pin on TRF7970 |
rwclough | 1:1eb96189824d | 28 | DigitalOut mod(p5); // Control MOD pin on TRF7970 |
rwclough | 1:1eb96189824d | 29 | DigitalOut enable(p4); // Control EN pin on TRF7970 |
rwclough | 1:1eb96189824d | 30 | DigitalOut enable2(p3); // Control EN2 pin on TRF7970 |
rwclough | 0:5622c60e9d3a | 31 | |
rwclough | 1:1eb96189824d | 32 | int buffer[2]; |
rwclough | 0:5622c60e9d3a | 33 | |
rwclough | 1:1eb96189824d | 34 | void blinkHeartbeatLED(void) { |
rwclough | 1:1eb96189824d | 35 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
rwclough | 1:1eb96189824d | 36 | // blinkHeartbeatLED() |
rwclough | 1:1eb96189824d | 37 | // Description: Toogle the heartbeat LED. |
rwclough | 1:1eb96189824d | 38 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
rwclough | 1:1eb96189824d | 39 | heartbeatLED = !heartbeatLED; |
rwclough | 1:1eb96189824d | 40 | } // End of blinkHeartbeatLED() |
rwclough | 0:5622c60e9d3a | 41 | |
rwclough | 1:1eb96189824d | 42 | void intHandler() { |
rwclough | 1:1eb96189824d | 43 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
rwclough | 1:1eb96189824d | 44 | // intHandler() |
rwclough | 1:1eb96189824d | 45 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
rwclough | 1:1eb96189824d | 46 | printf("Got Interrupt!\r\n"); |
rwclough | 1:1eb96189824d | 47 | } // End of intHandler() |
rwclough | 0:5622c60e9d3a | 48 | |
rwclough | 1:1eb96189824d | 49 | int main() { |
rwclough | 1:1eb96189824d | 50 | // Power up sequence |
rwclough | 1:1eb96189824d | 51 | CS = 0; enable2 = 0; enable = 0; |
rwclough | 1:1eb96189824d | 52 | wait_ms(2); |
rwclough | 1:1eb96189824d | 53 | CS = DESELECT; |
rwclough | 1:1eb96189824d | 54 | wait_ms(3); |
rwclough | 1:1eb96189824d | 55 | enable2 = 1; |
rwclough | 1:1eb96189824d | 56 | wait_ms(1); |
rwclough | 1:1eb96189824d | 57 | enable = 1; |
rwclough | 1:1eb96189824d | 58 | |
rwclough | 1:1eb96189824d | 59 | mod = 0; |
rwclough | 1:1eb96189824d | 60 | |
rwclough | 1:1eb96189824d | 61 | // Setup serial communication |
rwclough | 0:5622c60e9d3a | 62 | pc.baud(115200); |
rwclough | 1:1eb96189824d | 63 | printf("Initialization: "); |
rwclough | 1:1eb96189824d | 64 | |
rwclough | 1:1eb96189824d | 65 | // Setup heartbeat LED |
rwclough | 1:1eb96189824d | 66 | heartbeatLED = LED_OFF; |
rwclough | 1:1eb96189824d | 67 | Ticker heartbeat; |
rwclough | 1:1eb96189824d | 68 | heartbeat.attach(blinkHeartbeatLED, 1); |
rwclough | 1:1eb96189824d | 69 | printf("Heartbeat, "); |
rwclough | 1:1eb96189824d | 70 | |
rwclough | 1:1eb96189824d | 71 | // Setup the SPI interface |
rwclough | 1:1eb96189824d | 72 | spi.format(8, 3); // 8 bit data, mode = 3 |
rwclough | 1:1eb96189824d | 73 | spi.frequency(1000000); // SCLK = 1 MHz |
rwclough | 1:1eb96189824d | 74 | printf("SPI, "); |
rwclough | 1:1eb96189824d | 75 | |
rwclough | 1:1eb96189824d | 76 | // Set On-Off Keying modulation |
rwclough | 1:1eb96189824d | 77 | ook_ask = 1; |
rwclough | 1:1eb96189824d | 78 | printf("OOK, "); |
rwclough | 1:1eb96189824d | 79 | |
rwclough | 1:1eb96189824d | 80 | // Establish communication with the TRF7970 |
rwclough | 1:1eb96189824d | 81 | firstComm(); |
rwclough | 1:1eb96189824d | 82 | printf("Communication established, "); |
rwclough | 1:1eb96189824d | 83 | |
rwclough | 1:1eb96189824d | 84 | // Setup interrupt from TRF7970 |
rwclough | 1:1eb96189824d | 85 | readerInt.rise(&intHandler); // Interrupt on rising edge, call intHandler() |
rwclough | 1:1eb96189824d | 86 | printf("Interrupt enabled, "); |
rwclough | 1:1eb96189824d | 87 | |
rwclough | 1:1eb96189824d | 88 | printf("finished initialization.\r\n"); |
rwclough | 1:1eb96189824d | 89 | |
rwclough | 1:1eb96189824d | 90 | // Begin Test |
rwclough | 1:1eb96189824d | 91 | buffer[0] = RAM_0; // Address 0x12 |
rwclough | 1:1eb96189824d | 92 | buffer[1] = 0x55; |
rwclough | 1:1eb96189824d | 93 | writeSingle(buffer, 2); |
rwclough | 1:1eb96189824d | 94 | wait_ms(100); |
rwclough | 1:1eb96189824d | 95 | readSingle(buffer, 1); |
rwclough | 1:1eb96189824d | 96 | printf("Reg[0]: 0x%X\r\n", buffer[0]); |
rwclough | 1:1eb96189824d | 97 | printf("Reg[1]: 0x%X\r\n", buffer[1]); |
rwclough | 1:1eb96189824d | 98 | |
rwclough | 1:1eb96189824d | 99 | buffer[0] = RAM_0; // Address 0x12 |
rwclough | 1:1eb96189824d | 100 | buffer[1] = 0xAA; |
rwclough | 1:1eb96189824d | 101 | writeSingle(buffer, 2); |
rwclough | 1:1eb96189824d | 102 | wait_ms(100); |
rwclough | 1:1eb96189824d | 103 | readSingle(buffer, 1); |
rwclough | 1:1eb96189824d | 104 | printf("Reg[0]: 0x%X\r\n", buffer[0]); |
rwclough | 1:1eb96189824d | 105 | printf("Reg[1]: 0x%X\r\n", buffer[1]); |
rwclough | 1:1eb96189824d | 106 | // End Test |
rwclough | 1:1eb96189824d | 107 | |
rwclough | 1:1eb96189824d | 108 | wait(1); |
rwclough | 1:1eb96189824d | 109 | |
rwclough | 1:1eb96189824d | 110 | while(TRUE) { |
rwclough | 1:1eb96189824d | 111 | printf("Got here . . . Yeah!\r\n"); |
rwclough | 1:1eb96189824d | 112 | wait_ms(1000); |
rwclough | 0:5622c60e9d3a | 113 | } |
rwclough | 1:1eb96189824d | 114 | } // End of main() |