interrupt handling
Diff: readerComm.cpp
- Revision:
- 11:d5e8f47880f1
- Parent:
- 10:98a58968dc7d
- Child:
- 13:16a5b43ac874
diff -r 98a58968dc7d -r d5e8f47880f1 readerComm.cpp --- a/readerComm.cpp Thu Apr 09 22:09:35 2015 +0000 +++ b/readerComm.cpp Fri Apr 10 23:14:55 2015 +0000 @@ -38,7 +38,7 @@ #include "mbed.h" #include "readerComm.h" - +uint8_t sg=0; DigitalOut EN(p4); // Control EN pin on TRF7970 DigitalOut EN2(p3); // Control EN2 pin on TRF7970 DigitalOut CS(p19); @@ -47,8 +47,10 @@ extern uint8_t noBytes; extern SPI spi; // main.cpp extern Serial pc; // main.cpp -extern uint8_t buf[300]; // main.cpp -extern uint8_t found; +uint8_t buf[300]; // main.cpp +uint8_t found=0; +//extern bool tagFound=0; + extern DigitalOut debug1LED; extern DigitalOut debug2LED; extern DigitalOut ISO15693LED; @@ -57,10 +59,7 @@ uint8_t temp; uint8_t command[2]; -//standby -//powerdown -//sleep -// +uint8_t WAIT=0; void trf797xDirectCommand(uint8_t *buffer) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // trf797xDirectCommand() @@ -198,40 +197,36 @@ EN = 1; } void PowerUpNFC(void) -{//CS = 1; +{ //CS = 1; // wait_ms(4); // EN = 1; -// EN2=1; -//CS=1; -//wait_ms(1); -//EN = 1; -NFC_ON; -//wait_ms(1); -//EN2=0; - -//wait_ms(1); - //EN2= 0; +EN2 = 1; +wait_ms(1); +EN=1; } void PowerDownNFC(void) {///CS=1; - NFC_OFF; + EN=0; + EN2=0; //wait_ms(1); //EN2= 0; PowerDown Mode //EN2=1; SleepMode //CS=0; } +void SleepNFC(void) +{ EN=0; + EN2=0; + } void StandByNFC(void) -{//NFC_ON; +{ turnRFOn[0] = CHIP_STATUS_CONTROL; turnRFOn[1] = CHIP_STATUS_CONTROL; turnRFOn[1] &= 0x3F; -//#if NFC_STANDBY//standby -//turnRFOn[1] |= 0xA0; -//#elif NFC_ACTIVE//active mode turnRFOn[1] |= 0x80; -//#endif -trf797xWriteSingle(turnRFOn, 2);} +trf797xWriteSingle(turnRFOn, 2); +} + void SpiInit1(void) { spi.format(8, 1); // 8 bit data, mode = 1 (transition on rising edge, sample on falling edge) @@ -345,7 +340,7 @@ buf[6]=0x01; buf[7]=0x00; trf797xRawWrite(&buf[0],8); -wait_ms(2); +//wait_ms(2); testcommand[0] = IRQ_STATUS; trf797xReadSingle(testcommand,1); testcommand[0] = IRQ_STATUS; @@ -375,21 +370,35 @@ //wait(1); } -void PollNFC(uint8_t *irqStatus) -{// printf - if(*irqStatus==BIT6) - { found=1;} - //else if (*irqStatus==BIT1) -// found=3; -else {found=3;} +void FindNFC(uint8_t *irqStatus) +{//found=0; +//static uint8_t sg; +//printf("%X \r\n", *irqStatus); + + switch(*irqStatus) + {case BIT0: found=BIT0; WAIT=10; break; + case BIT1: found=BIT1; break; + // case BIT2://found=BIT2; // break; + //case BIT3:found=BIT3; WAIT=0;break; +// case BIT4:found=BIT4; WAIT=0;break; +// case BIT5:found=BIT5; WAIT=0;break; + case 0x40: found=0x40; break; + case BIT7: found=BIT7; break; + default: found=0; +} + + } void handlerNFC(void) { testcommand[0] = IRQ_STATUS; trf797xReadSingle(testcommand,1); -PollNFC(testcommand); -testcommand[0] = IRQ_STATUS; -trf797xReadSingle(testcommand,1); +FindNFC(testcommand); +//wait_ms(1); +//=============================use if trf7970a irq_status is not cleared +//testcommand[0] = IRQ_STATUS; +//trf797xReadSingle(testcommand,1); +//============================= } @@ -407,12 +416,14 @@ 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(2); +//testPin=1; +//=========================use to clear irq_status register of trf7970a +//testcommand[0] = IRQ_STATUS; +//trf797xReadSingle(testcommand,1); +//testcommand[0] = IRQ_STATUS; +//trf797xReadSingle(testcommand,1); +//========================== wait_ms(5); } void ReadNFC(void) @@ -428,13 +439,71 @@ noBytes = 0x7F & noBytes; // Determine the number of bytes left in FIFO buf[0] = FIFO; trf797xReadContinuous(&buf[0],noBytes); -//testPin=0; -testcommand[0] = IRQ_STATUS; -trf797xReadSingle(testcommand,1); -testcommand[0] = IRQ_STATUS; -trf797xReadSingle(testcommand,1); +//==use if trf7970a irq_status is not cleared +//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); } + +bool PollNFC(void) +{ +CS=1; +PowerUpNFC(); +//////wait_ms(1); +NFCInit(); +RegisterReInitNFC(); +MemReadReqNFC(); //InventoryReqNFC() + +wait_ms(WAIT); + +switch(found) +{case BIT0: + printf("no response:"); + printf("%X \r\n",found); + found=0; + WAIT=0; + break; +// //case BIT1: +// //case BIT2: +// //case BIT3: +//// case BIT4: +//// case BIT5: + case BIT6: + ReadNFC(); + PowerDownNFC(); //SleepNFC() //StandByNFC() + found=1; + WAIT=0; + break; + case BIT7: + printf("tx complete:"); + printf("%X \r\n",found); + found=0; + WAIT=0; +break; +default: found=0; +} +// +// +////InventoryReqNFC(); +////if(found==1) +////{ +////ReadNFC(); +////printf("tag id:"); +////for(uint8_t i=0; i<noBytes; i++) +////printf("%X ", buf[i]); +////printf("\r\n"); +////found=0; +////} +////else +//{printf("tnf2 \r\n"); +//} + +return found; + +} \ No newline at end of file