interrupt handling
Diff: main.cpp
- Revision:
- 6:3c510c297e2f
- Parent:
- 5:93c612f43ec2
- Child:
- 7:96baf1b2fd07
--- a/main.cpp Wed Apr 01 22:06:40 2015 +0000 +++ b/main.cpp Thu Apr 02 21:10:48 2015 +0000 @@ -20,7 +20,7 @@ //#include "NFC_7970.h" #include "readerComm.h" #include "interruptStuff.h" - +#include "HardwareTimer.h" SPI spi(p25, p28, p29); // MOSI, MISO, SCLK // Slave Select (SS) Serial pc(USBTX, USBRX); // Serial communication over USB with PC @@ -51,280 +51,32 @@ extern uint8_t turnRFOn[2]; extern uint8_t testcommand[2]; -void blinkHeartbeatLED(void) -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// blinkHeartbeatLED() -// Description: Toogle the heartbeat LED. -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -{ - heartbeatLED = !heartbeatLED; -} // End of blinkHeartbeatLED() + int main() -{pc.baud(115200); - PowerUpNFC(); - // Power up sequence. See TRF7970A datasheet "SLOU43K August 2011 Revised April 20914" Figures 6-3 and 6-4. - SpiInit1(); - NFCInit(); - SpiInit2(); - wait_ms(15); - -turnRFOn[0] = CHIP_STATUS_CONTROL; -turnRFOn[1] = CHIP_STATUS_CONTROL; +{ +pc.baud(115200); +PowerUpNFC(); +SpiInit(); //spi=1Mhz +NFCInit(); +wait_ms(1); +RegisterReInitNFC(); +RegistersReadNFC(); // -//trf797xReadSingle(&turnRFOn[1], 1); -turnRFOn[1] &= 0x3F; -turnRFOn[1] |= 0x2C; -// Oroiginal code has 0x20 !!! -trf797xReadSingle(turnRFOn, 1); -turnRFOn[0] = CHIP_STATUS_CONTROL; -turnRFOn[1] = CHIP_STATUS_CONTROL; - -turnRFOn[1] &= 0x3F; -turnRFOn[1] |= 0x2C; -trf797xWriteSingle(turnRFOn, 2); -wait_ms(2); - -testcommand[0] = ISO_CONTROL; -testcommand[1] = 0x02; // 6.78 MHz, OOK 100% -trf797xWriteSingle(testcommand, 2); -wait_ms(6); -// mod = 0; - testPin = 0; - // Setup serial communication - -// printf("\r\nInitialization: "); - -/* - // After power up sequence, Chip Status = 0x81, Regulator Control = 0x80 - *buffer = CHIP_STATUS_CONTROL; - spiReadContinuous(buffer, 2); - printf("\r\nChip Status: 0x%X\r\n", buffer[1]); - *buffer = REGULATOR_CONTROL; - spiReadContinuous(buffer, 2); - printf("Regulator Control: 0x%X\r\n", buffer[1]); -*/ - - heartbeatLED = LED_OFF; - ISO15693LED = LED_OFF; - debug1LED = LED_OFF; - debug2LED = LED_OFF; - -ook_ask.output(); // Set On-Off Keying modulation -ook_ask = 1; - -//****************************************** - -//testcommand[0] = ISO_CONTROL; -//testcommand[1] = 0x21; -//trf797xWriteSingle(testcommand, 2); -//testcommand[0] = IRQ_STATUS; -//trf797xReadContinuous(testcommand, 2); -//turnRFOn[0] = CHIP_STATUS_CONTROL; -//turnRFOn[1] = CHIP_STATUS_CONTROL; -//turnRFOn[1] &= 0x3F; -//turnRFOn[1] |= 0x21; -//trf797xWriteSingle(turnRFOn, 2); -//testcommand[0] = ISO_CONTROL; -//testcommand[1] = 0x00; -//trf797xWriteSingle(testcommand, 2); -//testcommand[0] = ISO_CONTROL; -//testcommand[1] = 0x00; -//trf797xWriteSingle(testcommand, 2); -//testcommand[0] = IRQ_STATUS; -//trf797xReadContinuous(testcommand, 2); -//turnRFOn[0] = CHIP_STATUS_CONTROL; -//trf797xReadSingle(&turnRFOn[0], 1); - -// -//turnRFOn[0] = CHIP_STATUS_CONTROL; -//turnRFOn[1] = CHIP_STATUS_CONTROL; -//turnRFOn[1] &= 0x3F; -//turnRFOn[1] |= 0x21; -//trf797xWriteSingle(turnRFOn, 2); -//testcommand[0] = IRQ_STATUS; -//trf797xReadContinuous(testcommand, 2); -//turnRFOn[0] = CHIP_STATUS_CONTROL; -//trf797xReadSingle(&turnRFOn[0], 1); -// -// -//turnRFOn[0] = CHIP_STATUS_CONTROL; -//turnRFOn[1] = CHIP_STATUS_CONTROL; -//turnRFOn[1] &= 0x3F; -//turnRFOn[1] |= 0x21; -//trf797xWriteSingle(turnRFOn, 2); -//testcommand[0] = IRQ_STATUS; -//trf797xReadContinuous(testcommand, 2); -//********************************************* - -RegisterReInitNFC(); - - -testcommand[0] = TX_TIMER_EPC_HIGH; -//testcommand[1] = 0xC1; -trf797xReadSingle(testcommand, 1); -testcommand[0] = TX_TIMER_EPC_LOW ; -//testcommand[1] = 0xC1; -trf797xReadSingle(testcommand, 1); -testcommand[0] = TX_PULSE_LENGTH_CONTROL ; -//testcommand[1] = 0x00; -trf797xReadSingle(testcommand, 1); -testcommand[0] = RX_NO_RESPONSE_WAIT_TIME ; -//testcommand[1] = 0x30; -trf797xReadSingle(testcommand, 1); -testcommand[0] = RX_WAIT_TIME ; -//testcommand[1] = 0x1F; -trf797xReadSingle(testcommand, 1); -testcommand[0] = MODULATOR_CONTROL ; -//testcommand[1] = 0x21; //0x34 100%ook@13MHz -trf797xReadSingle(testcommand, 1); -testcommand[0] = RX_SPECIAL_SETTINGS ; -//testcommand[1] = 0x40; -trf797xReadSingle(testcommand, 1); -testcommand[0] = REGULATOR_CONTROL ; -//testcommand[1] = 0x87; -trf797xReadSingle(testcommand, 1); - -//} +testPin=0; +while(1) +{InventoryReqNFC(); +//ReadNFC(); +//wait_ms(20); +} +} -//RegisterReInitNFC(); -// - /* ook_ask.input(); // Tri-state OOK pin -ook_ask.mode(PullUp);*/ -// -////readerInt.enable_irq(); -////======================================================================== -// - -while(1) -{ - -//send inventory command================================================== -buf[0]=0x8F; //Send Inventory(8B)[0x8F 0x91 0x3D 0x00 0x30 0x26 0x01 0x00] -buf[1]=0x91; -buf[2]=0x3D; -buf[3]=0x00; -buf[4]=0x30; -buf[5]=0x26; -buf[6]=0x01; -buf[7]=0x00; - -trf797xRawWrite(&buf[0],8); - -wait_ms(2); - -testcommand[0] = IRQ_STATUS; //Reset FIFO(0x0F/0x8F) -trf797xReadSingle(testcommand,1); -testcommand[0] = IRQ_STATUS; //Reset FIFO(0x0F/0x8F) -trf797xReadSingle(testcommand,1); -//wait_us(240); //Wait 2ms -//testcommand[0] = IRQ_STATUS; //Read/Clear IRQ Status(0x0C=>0x6C)+dummy read -//trf797xReadContinuous(testcommand, 2); -//testcommand[0] = RESET; //Reset FIFO(0x0F/0x8F) -//trf797xDirectCommand(testcommand); - - // Read second register as dummy read -// -wait_ms(5); -testcommand[0] = IRQ_STATUS; //Reset FIFO(0x0F/0x8F) -trf797xReadSingle(testcommand,1); -testcommand[0] = IRQ_STATUS; //Reset FIFO(0x0F/0x8F) -trf797xReadSingle(testcommand,1); - -testcommand[0] = IRQ_STATUS; //Reset FIFO(0x0F/0x8F) -trf797xReadSingle(testcommand,1); -testcommand[0] = RSSI_LEVELS; //Read RSSI levels and oscillator status(0x0F/0x4F) -trf797xReadSingle(testcommand, 1); -testcommand[0] = FIFO_CONTROL; //Read FIFO Status Register(0x1C/0x5C) -trf797xReadSingle(testcommand, 1); -// // Determine the number of bytes left in FIFO -testcommand[0] = 0x7F & testcommand[0]; -// -////buf[rxtxState] = FIFO; -buf[100] = FIFO; -//////testPin=1; // Write the received bytes to the correct place in the buffer -trf797xReadContinuous(&buf[100], testcommand[0]); -////testPin=0; -//testcommand[0] = RESET; //Reset FIFO(0x0F/0x8F) -//trf797xDirectCommand(testcommand); - -//testcommand[0] = 0x96; //DISABLE REVEIVER -//trf797xDirectCommand(testcommand); -////====================================================================8 clk cycles -////testcommand[0] = IDLE; -////trf797xDirectCommand(testcommand); -// -// -////==================================================================== -//testcommand[0] = 0x97; //ENABLE RECEIVER -//trf797xDirectCommand(testcommand); -////testcommand[0] = IDLE; -////trf797xDirectCommand(testcommand); - -//====================================================================8 clk cycles - -//====================================================================8 clk cycles -//testcommand[0] = IDLE; -//trf797xDirectCommand(testcommand); -//==================================================================== - -// -//// -//// -//// -//buf[8] = FIFO; // Write the received bytes to the correct place in the buffer -//// -//trf797xReadContinuous(&buf[8], 10);//Read Continuous FIFO from 0x1F to 0x1F+0x0A(0x1F/0x7F) -//// -//// //Wait 10 ms -//testcommand[0] = IRQ_STATUS; //Read/Clear IRQ Status(0x0C=>0x6C)+dummy read -//trf797xReadContinuous(testcommand, 2); // Read second register as dummy read -//testcommand[0] = FIFO_CONTROL; //Read FIFO Status Register(0x1C/0x5C) -//trf797xReadSingle(testcommand, 1); -//testcommand[0] = RESET; //Reset FIFO(0x0F/0x8F) -//trf797xDirectCommand(testcommand); // FIFO must be reset before receiving the next response -testcommand[0] = RSSI_LEVELS; //Read RSSI levels and oscillator status(0x0F/0x4F) -trf797xReadSingle(testcommand, 1); -testcommand[0] = RESET; //Reset FIFO(0x0F/0x8F) -trf797xDirectCommand(testcommand); -//trf797xStopDecoders(); -//trf797xRunDecoders(); -//testcommand[0] = 0x94; //Reset FIFO(0x0F/0x8F) -//trf797xDirectCommand(testcommand); - -//testcommand[0] = IRQ_STATUS; -//trf797xReadContinuous(testcommand, 2); - - -}} // Read RSSI levels -//testcommand[0] = RESET; //Reset FIFO(0x0F/0x8F) -//trf797xDirectCommand(testcommand); //RESET - -//========================================================================= - - -//}// end of while -//}// end of main -/*========================================================================== -Initialize the chipset ISO15693 and read UID: -1) Reset -[0x83] -2) Write Modulator and SYS_CLK Control Register (0x09) (13.56Mhz SYS_CLK and default Clock 13.56Mhz)) -[0x09 0x31] -3) Configure Mode ISO Control Register (0x01) to 0x02 (ISO15693 high bit rate, one subcarrier, 1 out of 4) -[0x01 0x02] -4) Turn RF ON (Chip Status Control Register (0x00)) -[0x40 r] [0x00 0x20] [0x40 r] -5) Inventory Command (see Figure 5-20. Inventory Command Sent From MCU to TRF7970A) -5-1) Send Inventory(8B), Wait 2ms, Read/Clear IRQ Status(0x0C=>0x6C)+dummy read, Read FIFO Status Register(0x1C/0x5C), Read Continuous FIFO from 0x1F to 0x1F+0x0A(0x1F/0x7F), Read/Clear IRQ Status(0x0C=>0x6C)+dummy read, Read FIFO Status Register(0x1C/0x5C), Reset FIFO(0x0F/0x8F), Read RSSI levels and oscillator status(0x0F/0x4F) -[0x8F 0x91 0x3D 0x00 0x30 0x26 0x01 0x00] %:2 [0x6C r:2] [0x5C r] [0x7F r:10] %:10 [0x6C r:2] [0x5C r] [0x8F] [0x4F r] -==============================================================================*/