interrupt handling

Dependencies:  

Revision:
6:3c510c297e2f
Parent:
5:93c612f43ec2
Child:
7:96baf1b2fd07
--- a/readerComm.cpp	Wed Apr 01 22:06:40 2015 +0000
+++ b/readerComm.cpp	Thu Apr 02 21:10:48 2015 +0000
@@ -13,6 +13,28 @@
     0.0     2015-02-27  RWC     Original version.
     
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*==========================================================================
+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]
+==============================================================================*/   
+
+
+
+
+
 
 #include    "mbed.h"
 #include    "readerComm.h"
@@ -52,66 +74,7 @@
 extern  uint8_t     debugBuffer[1000];  // Capture data for analysis
 extern  uint8_t     bufIdx;
 
-void trf797xInitialSettings(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xInitialSettings()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{
-    uint8_t mod_control[2];
-    
-    mod_control[0] = SOFT_INIT;
-    trf797xDirectCommand(mod_control);
-    
-    mod_control[0] = IDLE;
-    trf797xDirectCommand(mod_control);
-    
-    mod_control[0] = MODULATOR_CONTROL;
-    mod_control[1] = 0x21;                  // 6.78 MHz, OOK 100%
-    trf797xWriteSingle(mod_control, 2);
-    
-    mod_control[0] = MODULATOR_CONTROL;
-    trf797xReadSingle(mod_control, 1);
-//    printf("\r\nMOD: 0x%02X 0x%02X\r\n", mod_control[0], mod_control[1]);
-    
-    /*
-    mod_control[0] = CHIP_STATUS_CONTROL;
-    mod_control[1] = 0x01;
-    trf797xWriteSingle(mod_control, 2);
-    
-    mod_control[0] = CHIP_STATUS_CONTROL;
-    trf797xReadSingle(mod_control, 1);
-    printf("CHIP: 0x%02X 0x%02X\r\n", mod_control[0], mod_control[1]);
-    
-    mod_control[0] = ISO_CONTROL;
-    mod_control[1] = 0x02;
-    trf797xWriteSingle(mod_control, 2);
-    
-    mod_control[0] = ISO_CONTROL;
-    mod_control[1] = ISO_CONTROL;
-    trf797xReadSingle(mod_control, 1);
-    printf("ISO: 0x%02X 0x%02X\r\n", mod_control[0], mod_control[1]);
-    
-    mod_control[0] = RX_SPECIAL_SETTINGS;
-    mod_control[1] = 0x40;
-    trf797xWriteSingle(mod_control, 2);
-    
-    mod_control[0] = RX_SPECIAL_SETTINGS;
-    mod_control[1] = RX_SPECIAL_SETTINGS;
-    trf797xReadSingle(mod_control, 1);
-    printf("RX: 0x%02X 0x%02X\r\n", mod_control[0], mod_control[1]);
-    */
-    /*
-    command[0] = CHIP_STATUS_CONTROL;
-    command[1] = CHIP_STATUS_CONTROL;
-    command[1] = 0x01;                  // Set bit 0 => Vin = 5V
-    trf797xWriteSingle(command, 2);
 
-    command[0] = CHIP_STATUS_CONTROL;
-    command[1] = CHIP_STATUS_CONTROL;
-    trf797xReadSingle(command, 1);
-    printf("CHIP 0x%02X  0x%02X\r\n", command[0], command[1]);
-    */
-}   // End of trf797xInitialSettings()
 
 void trf797xDirectCommand(uint8_t *buffer)
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -234,343 +197,14 @@
     trf797xDirectCommand(command);
 }
 
-void trf797xTxNextSlot(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xTxNextSlot()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{
-    command[0] = TRANSMIT_NEXT_SLOT;
-    trf797xDirectCommand(command);
-}
-
-void trf797xDisableSlotCounter(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xDisableSlotCounter()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{
-    buf[40] = IRQ_MASK;
-    buf[41] = IRQ_MASK;
-    trf797xReadSingle(&buf[41], 1);
-    buf[41] &= 0xFE;
-    trf797xWriteSingle(&buf[40], 2);
-}
-
-void trf797xReset(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xReset()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{
-    command[0] = RESET;
-    trf797xDirectCommand(command);
-}
-
-void trf797xTurnRfOn(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xTurnRfOn()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{   
-    command[0] = CHIP_STATUS_CONTROL;
-    command[1] = CHIP_STATUS_CONTROL;
-    trf797xReadSingle(&command[1], 1);
-    command[1] &= 0x3F;
-    command[1] |= 0x21; // Oroiginal code has 0x20 !!!
-//    printf("\r\nCHIP 0x%02X  0x%02X\r\n", command[0], command[1]);
-    trf797xWriteSingle(command, 2);
-//    printf("\r\nCHIP 0x%02X  0x%02X\r\n", command[0], command[1]);
-}   // End of trf797xTurnRfOn()
-
-void trf797xTurnRfOff(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xTurnRfOff()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{
-    command[0] = CHIP_STATUS_CONTROL;
-    command[1] = CHIP_STATUS_CONTROL;
-    trf797xReadSingle(&command[1], 1);
-    command[1] &= 0x1F;
-    trf797xWriteSingle(command, 2);
-}   // End of trf797xTurnRfOff()
-
-void trf797xWriteIsoControl(uint8_t iso_control)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  trf797xWriteIsoControl()
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{
-    uint8_t write[4];
-    
-    if ((iso_control & BIT5) == BIT5) {
-        printf("iso_control bit5 != 0\r\n");
-        return;
-    }
-    
-    write[0] = ISO_CONTROL;
-    write[1] = iso_control;
-    write[1] &= ~BIT5;
-    trf797xWriteSingle(write, 2);
-    iso_control &= 0x1F;
-}   // End of trf797xWriteIsoControl()
-
-void iso15693FindTag(void)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  iso15693FindTag()
-//  Description:    Used to detect ISO15693 conforming tags.
-//                  If an ISO15693 conforming tag is found ISO15693LED is turned ON.
-//                  1) Turn RF ON
-//                  2) Perform a complete anticollision sequence
-//                  3) Turn RF OFF
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{  // testPin=1;
-    trf797xTurnRfOn();
-   // testPin=0;
-    //=======================================================diable interrupt from trf797x 
-   //  readerInt.disable_irq();                                // comment: has no effect in detectecting interrupt from trf797x, works without disabling too $SG
-    //=======================================================diable interrupt from trf797x  $SG
-   // testPin=1;
-    trf797xWriteIsoControl(0x02);
-   // testPin=0;
-    wait_ms(6); // The VCD should wait at least 1 ms after it activated the
-                // powering field before sending the first request, to
-                // ensure that the VICCs are ready to receive it. (ISO15693-3)
-    /*
-    //  Field Level Test:
-    buffer[0] = RUN_DECODERS;   // Enable receiver
-    trf797xDirectCommand(buffer);
-    buffer[0] = CHIP_STATUS_CONTROL;
-    buffer[1] = 0x23;
-    trf797xWriteSingle(buffer, 2);
-    wait_ms(1);
-    buffer[0] = CHECK_INTERNAL_RF;
-    trf797xDirectCommand(buffer);
-    buffer[0] = RSSI_LEVELS;
-    trf797xReadSingle(buffer, 1);
-    printf("RSSI: 0x%X\r\n", buffer[0]);
-    //  Result: RSSI = 0x5C (Range is 0x40 to 0x7F)
-    */
-    
-    flags = SIXTEEN_SLOTS;                  // SIXTEEN_SLOTS = 0x06
-//    flags = ONE_SLOT;                       // ONE_SLOT = 0x26
-    buf[20] = 0x00;
-  //  debug2LED = LED_ON;
-      
-    iso15693Anticollision(&buf[20],0x00);  // Send Inventory request
-    
-    trf797xTurnRfOff();
-    trf797xResetIrqStatus();   
-                    // Clear any IRQs
-}   // End of iso15693FindTag()
-
-void iso15693Anticollision(uint8_t *mask, uint8_t length)
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-//  iso15693Anticollision()
-//  Description: Used to perform an inventory cycle of 1 or 16 timeslots.
-//               Send command, receive response and send response to host.
-//  Parameters: *mask =     mask value
-//              length =    number of significant bits of mask value
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-{   
-    uint8_t     i = 1, j = 1, command[2], no_slots, found = 0;
-    uint8_t     *p_slot_no, slot_no[17];
-    uint8_t     new_mask[8], new_length, mask_size;
-    uint32_t    size;
-    uint8_t     fifo_length = 0;
-    uint16_t    k = 0;
-//    uint8_t     irqStatus[2], iso_control;
-
-    slot_no[0] = 0x00;
-    if ((flags & BIT5) == 0x00) {                       // flags<5> is the number of slots testPin
-        no_slots = 16;                                  // 16 slots if flags<5> is cleared
-    }
-    else {
-        no_slots = 1;                                   // 1 slot if flags<5> is set
-    }
-    
-    p_slot_no = &slot_no[0];                            // slot number pointer
-    mask_size = (((length >> 2) + 1) >> 1);             // mask_size is 1 for length = 4 or 8
-    buf[0] = 0x8F;                                      // RESET
-    buf[1] = 0x91;                                      // send with CRC
-    buf[2] = 0x3D;                                      // write continuous from 1D
-    buf[5] = flags;                                     // ISO15693 flags
-    buf[6] = 0x01;                                      // anticollision command code
-    
-    if (flags & 0x10) {                                 // mask_size is 2 for length = 12 or 16 and so on
-        size = mask_size + 4;                           // mask value + mask length + afi + command code + flags
-        buf[7] = afi;
-        buf[8] = length;                                // mask length
-        if (length > 0) {
-            for(i = 0; i < mask_size; i++) {
-                buf[9 + i] = *(mask + i);
-            }
-        }
-        fifo_length = 9;
-    }
-    else {                                              // mask_size is 2 for length = 12 or 16 and so on
-        size = mask_size + 3;                           // mask value + mask length + command code + flags
-        buf[7] = length;                                // mask length
-        if(length > 0) {
-            for(i = 0; i < mask_size; i++) {
-                buf[8 + i] = *(mask + i);
-            }
-        }
-        fifo_length = 8;
-    }
-    
-    buf[3] = (char) (size >> 8);
-    buf[4] = (char) (size << 4);
-  
-  
-    
-    trf797xResetIrqStatus();
-   
-    //  ***** Original code sets up a 30 ms counter here *****
-    //  ***** Original code enables IRQ here *****
-    //  ***** nRF51422 clear IRQ register *****
-    readerInt.enable_irq();
-    
-    trf797xRawWrite(&buf[0], mask_size + fifo_length);      // Write to FIFO
-    
-    //===================================================runs till here !$SG
-    irqRegister = 0x01;
-    irqFlag = 0x00; 
-   
-    
- 
-    //
-   for (j = 1; j <= no_slots; j++) {                     // 1 or 16 available timeslots
-       rxtxState = 1;
-        //  ***** Original code sets up a 20 ms counter and starts it here *****
-        //irqFlag = 0x00;
-      // while(1)
-        while(irqFlag == 0x00)
-        { ; 
-        }  
-        
-     //  ISO15693LED = LED_ON;
-      //  wait_ms(1000); 
-     //  ISO15693LED = LED_OFF;  
-       irqRegister = 0x01;
-                               // Wait for interrupt
-        //  ***** Original code stops the counter here *****
-  //      
-        while(irqRegister == 0x01) {                    // Wait for RX complete
-            k++;
-           if (k == 0xFFF0) { //printf("k == 0xFFF0 _MAIN \r\n");  
-               irqRegister = 0x00;
-                rxErrorFlag = 0x00;
-            }
-       }
-
-
-
-
-//wait_us(1000);
-
-        command[0] = RSSI_LEVELS;                       // Read RSSI levels
-        trf797xReadSingle(command, 1);
-        
-        switch (irqRegister) {
-            case 0xFF:                  // If received UID in buffer             //0xff changed to 0x01 $SG
-               found = 1;
-                printf("\r\nISO15693: [ ");
-                for (i=3; i < 11; i++) {
-                    printf("%c", buf[i]);
-                }
-                printf(", %d ]\r\n", command[0]);
-            break;
-            
-            case 0x02:   printf("collision occured _MAIN \r\n");               // Collision occurred
-                p_slot_no++;            // Remember a collision was detected
-                *p_slot_no = j;
-            break;
-            
-            case 0x00:    // printf("Timer interrupt \r\n");             // Timer interrupt
-               //  ***** Original code does nothing! *****
-            break;
-            
-           default:
-                //  ***** Original code does nothing *****
-            break;
-        }   // switch (irqRegister)
-        
-        command[0] = RESET;             // FIFO must be reset before receiving the next response
-        trf797xDirectCommand(command);
-        
-        if ((no_slots == 16) && (j < 16)) {         // If 16 slots used then send EOF (next slot)
-            trf797xStopDecoders();
-            trf797xRunDecoders();
-            command[0] = RESET;                 // new
-            trf797xDirectCommand(command);      // new
-           trf797xTxNextSlot();   // RESET must precede txNextSlot, see "TRF7970A FW Design Hints SLOA159.
-        }
-        else if ((no_slots == 16) && (j == 16)) {   // At end of slot 16, stop the slot counter
-            trf797xStopDecoders();
-            trf797xDisableSlotCounter();
-        }
-        else if (no_slots == 1) {                   // 1 slot is used
-           break;
-        }
-    }   // for (j = 1; j <= no_slots; j++)
-   //================================================ 
-   //===================================================
-    if (found == 1) {
-        ISO15693LED = LED_ON;
-   }
-   else {printf("tag not read \r\n");
-      ISO15693LED = LED_OFF;
-   }
-//    
-    new_length = length + 4;                        // The mask length is a multiple of 4 bits
-    mask_size = (((new_length >> 2) + 1) >> 1);
-   while ((*p_slot_no != 0x00) && (no_slots == 16) && (new_length < 61) && (slot_no[16] != 16)) {
-        *p_slot_no = *p_slot_no - 1;
-
-       for(i = 0; i < 8; i++)
-        {
-           new_mask[i] = *(mask + i);              // First the whole mask is copied
-       }
-
-       if((new_length & BIT2) == 0x00)
-        {
-            *p_slot_no = *p_slot_no << 4;
-        }
-        else
-        {
-            for(i = 7; i > 0; i--)
-           {
-               new_mask[i] = new_mask[i - 1];
-           }
-           new_mask[0] &= 0x00;
-       }
-        new_mask[0] |= *p_slot_no;                  // The mask is changed
-       wait_ms(2);
-
-
-        printf("Idx: 0x%02X  Buf: 0x%02X,  ", bufIdx, debugBuffer[bufIdx-1]);
-
-       iso15693Anticollision(&new_mask[0], new_length);    // Recursive call with new Mask
-
-       p_slot_no--;
-       
-   }
-    //==================================================
-    //  ***** Original code disables IRQ here *****
-    //readerInt.disable_irq();
-  //debug2LED = LED_OFF;
-}   // End of iso15693Anticollision()
-/*
-    Header file for main.cpp
-*/
-
 
 void PowerUpNFC(void)
-{// CS = 0; enable2 = 0; enable = 0;
-   CS = 1;
-   wait_ms(8);
-   // 
-   // wait_ms(3);
-   // enable2 = 1;
-   // wait_ms(3);
-    enable = 1;
-  
+{CS = 1;
+ wait_ms(4);
+ enable = 1;
+}
+void PowerDownNFC(void)
+{enable = 0;
 }
 
 void SpiInit1(void)
@@ -579,60 +213,45 @@
 spi.frequency(250000);  
 }
 
-void SpiInit2(void)
+void SpiInit(void)
 {
 spi.format(8, 1);       // 8 bit data, mode = 1 (transition on rising edge, sample on falling edge)
 spi.frequency(1000000);  
 }
 
 void NFCInit(void)
-{wait_ms(2);
-    //RESET =================================================================
-//testcommand[0]=RESET;
-//trf797xDirectCommand(testcommand); 
-//=======================================================================
-
-
+{
+//wait_ms(2);
 testcommand[0] = SOFT_INIT;
 trf797xDirectCommand(testcommand); 
- wait_ms(2);
+wait_ms(2);
 testcommand[0] = IDLE;
 trf797xDirectCommand(testcommand); 
 wait_ms(2);
-//testcommand[0] = IDLE;
-//trf797xDirectCommand(testcommand); 
-////Write Modulator and SYS_CLK Control Register (0x09) ====================
-////(13.56Mhz SYS_CLK and default Clock 13.56Mhz))==========================
 testcommand[0] = MODULATOR_CONTROL;
 testcommand[1] = 0x21;                  // 6.78 MHz, OOK 100%
 trf797xWriteSingle(testcommand, 2);
-//////========================================================================
-wait_ms(2);
-
+//wait_ms(2);
 testcommand[0] = MODULATOR_CONTROL;             
 trf797xReadSingle(testcommand, 1);
-//====================================================================8 clk cycles
-//testcommand[0] = IDLE;
-//trf797xDirectCommand(testcommand); 
-//testcommand[0] = IDLE;
-//trf797xDirectCommand(testcommand);
-//====================================================================
-////Turn RF ON (Chip Status Control Register (0x00))========================
-
-//Configure Mode ISO Control Register (0x01) to 0x02====================== 
-//(ISO15693 high bit rate, one subcarrier, 1 out of 4)====================
+turnRFOn[0] = CHIP_STATUS_CONTROL;
+turnRFOn[1] = CHIP_STATUS_CONTROL;
+turnRFOn[1] &= 0x3F;
+turnRFOn[1] |= 0x20;
+// Oroiginal code has 0x20 !!!
+trf797xReadSingle(turnRFOn, 1);
+turnRFOn[0] = CHIP_STATUS_CONTROL;
+turnRFOn[1] = CHIP_STATUS_CONTROL;
 
-//testcommand[0]=0x0F;//reset
-//trf797xDirectCommand(testcommand);
-//====================================================================8 clk cycles
-//testcommand[0] = IDLE;
-//trf797xDirectCommand(testcommand); 
-//testcommand[0] = IDLE;
-//trf797xDirectCommand(testcommand);
-
-//====================================================================
-
-////========================================================================
+turnRFOn[1] &= 0x3F;
+turnRFOn[1] |= 0x20;
+trf797xWriteSingle(turnRFOn, 2);
+//wait_ms(2);
+ 
+testcommand[0] = ISO_CONTROL;
+testcommand[1] = 0x02;                  // 6.78 MHz, OOK 100%
+trf797xWriteSingle(testcommand, 2);
+//wait_ms(6); 
 }
 
 void RegisterReInitNFC(void)
@@ -649,15 +268,119 @@
 testcommand[1] = 0x30;                  
 trf797xWriteSingle(testcommand, 2);
 testcommand[0] =  RX_WAIT_TIME ;
-testcommand[1] = 0x0F;                  
+testcommand[1] = 0x1F;                  
 trf797xWriteSingle(testcommand, 2);
 testcommand[0] = MODULATOR_CONTROL ;
 testcommand[1] = 0x21;     //0x34 100%ook@13MHz             
 trf797xWriteSingle(testcommand, 2);
 testcommand[0] = RX_SPECIAL_SETTINGS ;
-testcommand[1] = 0x41;                  
+testcommand[1] = 0x40;                  
 trf797xWriteSingle(testcommand, 2);
 testcommand[0] = REGULATOR_CONTROL ;
 testcommand[1] = 0x87;                  
 trf797xWriteSingle(testcommand, 2);
+}
+
+
+void RegistersReadNFC(void)
+{
+testcommand[0] = TX_TIMER_EPC_HIGH;          //0xC1; 
+trf797xReadSingle(testcommand, 1);     
+testcommand[0] = TX_TIMER_EPC_LOW ;          //0xC1; 
+trf797xReadSingle(testcommand, 1);     
+testcommand[0] = TX_PULSE_LENGTH_CONTROL ;   //0x00; 
+trf797xReadSingle(testcommand, 1);  
+testcommand[0] = RX_NO_RESPONSE_WAIT_TIME  ; //0x30;
+trf797xReadSingle(testcommand, 1);              
+testcommand[0] =  RX_WAIT_TIME ;             //0x1F;
+trf797xReadSingle(testcommand, 1);  
+testcommand[0] = MODULATOR_CONTROL ;         //0x21; 
+trf797xReadSingle(testcommand, 1);    
+testcommand[0] = RX_SPECIAL_SETTINGS ;       //0x40;
+trf797xReadSingle(testcommand, 1);
+testcommand[0] = REGULATOR_CONTROL ;        //0x87; 
+trf797xReadSingle(testcommand, 1);
+}
+
+void InventoryReqNFC(void)
+{
+//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;                  
+trf797xReadSingle(testcommand,1); 
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1);  
+wait_ms(5);
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1);
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1); 
+testcommand[0] = FIFO_CONTROL;           //Read FIFO Status Register(0x1C/0x5C)    
+trf797xReadSingle(testcommand, 1);
+testcommand[0] = 0x7F & testcommand[0];   // Determine the number of bytes left in FIFO
+buf[0] = FIFO;   
+trf797xReadContinuous(&buf[0], testcommand[0]);
+testcommand[0] = RSSI_LEVELS;            //Read RSSI levels and oscillator status(0x0F/0x4F)           
+trf797xReadSingle(testcommand, 1); 
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1); 
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1);  
+testcommand[0] = RESET;                  //Reset FIFO(0x0F/0x8F)
+trf797xDirectCommand(testcommand);  
+trf797xStopDecoders();
+trf797xRunDecoders();  
+//wait(1);
+}  
+//void PollNFC(void)
+//{
+//}
+
+void ReadNFC(void)
+{testcommand[0] = RX_NO_RESPONSE_WAIT_TIME  ;
+testcommand[1] = 0xFF;  
+trf797xWriteSingle(testcommand, 2);
+ //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]=0x02;
+buf[6]=0x20;
+buf[7]=0x00;
+trf797xRawWrite(&buf[0],8); 
+wait_ms(2); 
+testPin=1;
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1); 
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1);  
+wait_ms(5);
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1);
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1); 
+testcommand[0] = FIFO_CONTROL;           //Read FIFO Status Register(0x1C/0x5C)    
+trf797xReadSingle(testcommand, 1);
+testcommand[0] = 0x7F & testcommand[0];   // Determine the number of bytes left in FIFO
+buf[0] = FIFO;   
+trf797xReadContinuous(&buf[0], testcommand[0]);
+testPin=0;
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1); 
+testcommand[0] = IRQ_STATUS;                  
+trf797xReadSingle(testcommand,1);  
+testcommand[0] = RESET;                  //Reset FIFO(0x0F/0x8F)
+trf797xDirectCommand(testcommand);  
+//wait(1);   
 }
\ No newline at end of file