/* ======================================================================================================================= Function used for direct writing to reader chip ; ======================================================================================================================= */ void RAWwrite(unsigned char *pbuf, unsigned char lenght) { /*~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~*/ if ((SPIMODE)==0) //Parallel Mode { STARTcondition(); while(lenght > 0) { TRFWrite = *pbuf; /* send command */ //PortWrite(pbuf); TRF_DCLK_ON(); TRF_DCLK_OFF(); pbuf++; lenght--; } /* while */ STOPcont(); }//end Parallel Mode /**********************************************************************/ if (SPIMODE) { #ifndef SPI_BITBANG /*********************************/ /* Start of Hardware SPI Mode */ /*********************************/ TRF_SS_LOW(); //Start SPI Mode while(lenght > 0) { while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = *pbuf; // Previous data to TX, RX // while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; pbuf++; lenght--; } /* while */ // SPIStartCondition(); //SCLK High TRF_SS_HIGH(); //Stop SPI Mode // SPIStartCondition(); //SCLK High // P3SEL |= BIT3; //Revert Back // end added code #endif }//end of SPI Mode } /* RAWwrite */
/* ======================================================================================================================= Function writes a specified number of registers from ; a specified address upwards ; ======================================================================================================================= */ void WriteCont(unsigned char *pbuf, unsigned char lenght) { /*~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~*/ if ((SPIMODE)==0) //Parallel Mode { STARTcondition(); *pbuf = (0x20 | *pbuf); /* address, write, continous */ *pbuf = (0x3f &*pbuf); /* register address */ while(lenght > 0) { TRFWrite = *pbuf; /* send command */ //PortWrite(pbuf); TRF_DCLK_ON(); TRF_DCLK_OFF(); pbuf++; lenght--; } /* while */ STOPcont(); } //end of Parallel Mode if (SPIMODE) { #ifndef SPI_BITBANG /*********************************/ /* Start of Hardware SPI Mode */ /*********************************/ TRF_SS_LOW(); //Start SPI Mode *pbuf = (0x20 | *pbuf); /* address, write, continous */ *pbuf = (0x3f &*pbuf); /* register address */ while(lenght > 0) { while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = *pbuf; // Previous data to TX, RX while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; pbuf++; lenght--; } /* while */ TRF_SS_HIGH(); //Stop SPI Mode #endif } //end of SPI mode } /* WriteCont */
/* ======================================================================================================================= Function DirectCommand transmits a command to the reader chip ======================================================================================================================= */ void DirectCommand(unsigned char *pbuf) { /*~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~*/ if ((SPIMODE)==0) //Parallel Mode { STARTcondition(); *pbuf = (0x80 | *pbuf); /* command */ *pbuf = (0x9f &*pbuf); /* command code */ TRFWrite = *pbuf; /* send command */ //PortWrite(pbuf); TRF_DCLK_ON(); TRF_DCLK_OFF(); STOPcondition(); } if (SPIMODE) //SPI Mode { #ifndef SPI_BITBANG /*********************************/ /* Start of Hardware SPI Mode */ /*********************************/ TRF_SS_LOW(); //Start SPI Mode *pbuf = (0x80 | *pbuf); /* command */ *pbuf = (0x9f &*pbuf); /* command code */ while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = *pbuf; // Previous data to TX, RX // while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; SPIStartCondition(); //SCLK High // SPIStopCondition(); // SCLK Low // P3SEL |= BIT3; //Revert Back TRF_SS_HIGH(); //Stop SPI Mode P3SEL |= BIT3; //Revert Back #endif } } /* DirectCommand */
/* ======================================================================================================================= Direct mode (no stop condition) ; ======================================================================================================================= */ void DirectMode(void) { if ((SPIMODE)==0)//Parallel Mode { //OOKdirOUT; STARTcondition(); TRFWrite = ChipStateControl; //PortWriteSet(ChipStateControl); TRF_DCLK_ON(); TRF_DCLK_OFF(); TRFWrite = 0x61; /* write a 1 to BIT6 in register * 0x00; * */ //PortWriteSet(0x61); TRF_DCLK_ON(); TRF_DCLK_OFF(); TRFDirIN; /* put the PORT1 to tristate */ }//end of Parallel mode if (SPIMODE) //SPI Mode { #ifndef SPI_BITBANG //OOKdirOUT; TRF_SS_LOW(); //Start SPI Mode while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = ChipStateControl; // Previous data to TX, RX while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = 0x61; /* write a 1 to BIT6 in register * 0x00; * */ TRFDirIN; /* put the PORT1 to tristate */ #endif } //end of SPI Mode } /* DirectMode */
/* ======================================================================================================================= Direct mode (no stop condition) ; ======================================================================================================================= */ void DirectMode(void) { if ((SPIMODE)==0)//Parallel Mode { OOKdirOUT; STARTcondition(); TRFWrite = ChipStateControl; clkON; clkOFF; TRFWrite = 0x61; /* write a 1 to BIT6 in register * 0x00; * */ clkON; clkOFF; TRFDirIN; /* put the PORT1 to tristate */ }//end of Parallel mode if (SPIMODE) //SPI Mode { #ifndef SPI_BITBANG OOKdirOUT; SlaveSelectLOW; //Start SPI Mode while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = ChipStateControl; // Previous data to TX, RX while (!(IFG2 & UCB0RXIFG)); temp=UCB0RXBUF; while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = 0x61; /* write a 1 to BIT6 in register * 0x00; * */ TRFDirIN; /* put the PORT1 to tristate */ #endif } //end of SPI Mode } /* DirectMode */
/* ======================================================================================================================= Function reads specified number of registers from a ; specified address upwards. ; ======================================================================================================================= */ void ReadCont(unsigned char *pbuf, unsigned char lenght) { /*~~~~~~~~~~~~~~*/ unsigned char j; // unsigned char len1 = lenght; /*~~~~~~~~~~~~~~*/ if ((SPIMODE)==0) //Parallel Mode { STARTcondition(); *pbuf = (0x60 | *pbuf); /* address, read, continous */ *pbuf = (0x7f &*pbuf); /* register address */ TRFWrite = *pbuf; /* send command */ //PortWrite(pbuf); TRF_DCLK_ON(); TRF_DCLK_OFF(); TRFDirIN; /* read register */ /* * TRFWrite = 0x00; */ while(lenght > 0) { TRF_DCLK_ON(); /* * TRFDirIN; */ __no_operation(); *pbuf = PortRead; /* * TRFDirOUT; */ TRF_DCLK_OFF(); pbuf++; lenght--; } /* while */ STOPcont(); } //end of Parallel Mode if (SPIMODE) // { #ifndef SPI_BITBANG /*********************************/ /* Start of Hardware SPI Mode */ /*********************************/ // lenght=lenght+2; // unsigned char len1 = lenght; TRF_SS_LOW(); //Start SPI Mode *pbuf = (0x60 | *pbuf); /* address, read, continous */ *pbuf = (0x7f &*pbuf); /* register address */ while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = *pbuf; // Previous data to TX, RX //while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; UCB0CTL0 &= ~UCCKPH; //added length clause - May 9th 2007 if(*pbuf != 0x6C)//execute only when IRQRead is not called { if (lenght != 0x1F) { for (j=0;j<2;j++) { while (!(UCB1IFG & UCTXIFG)); UCB0TXBUF = 0x00; //Receive initiated by a dummy TX write while (!(UCB1IFG & UCRXIFG)); _NOP(); _NOP(); temp = UCB0RXBUF; } } } while(lenght > 0) { while (!(UCB1IFG & UCTXIFG)); UCB0TXBUF = 0x00; //Receive initiated by a dummy TX write while (!(UCB1IFG & UCRXIFG)); _NOP(); _NOP(); *pbuf = UCB0RXBUF; pbuf++; lenght--; } UCB0CTL0 |= UCCKPH; TRF_SS_HIGH(); //Stop SPI Mode #endif } //end of SPI mode } /* ReadCont */
/* ======================================================================================================================= Function reads only one register ; ======================================================================================================================= */ void ReadSingle(unsigned char *pbuf, unsigned char lenght) { /*~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~*/ if ((SPIMODE)==0) { STARTcondition(); while(lenght > 0) { *pbuf = (0x40 | *pbuf); /* address, read, single */ *pbuf = (0x5f &*pbuf); /* register address */ TRFWrite = *pbuf; /* send command */ //PortWrite(pbuf); TRF_DCLK_ON(); TRF_DCLK_OFF(); TRFDirIN; /* read register */ TRF_DCLK_ON(); __no_operation(); *pbuf = PortRead; TRF_DCLK_OFF(); TRFWrite = 0x00; //PortWriteSet(0x00); TRFDirOUT; pbuf++; lenght--; } /* while */ STOPcondition(); } //end of parallel mode /**************************************************************/ if (SPIMODE) //SPI Mode { #ifndef SPI_BITBANG /*********************************/ /* Start of Hardware SPI Mode */ /*********************************/ TRF_SS_LOW(); //Start SPI Mode while(lenght > 0) { *pbuf = (0x40 | *pbuf); /* address, read, single */ *pbuf = (0x5f & *pbuf); /* register address */ while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = *pbuf; // Previous data to TX, RX //while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; UCB0CTL0 &= ~UCCKPH; /////////////////////////////////SPIStartCondition();//SCLK High /////////////////////////////////P3SEL |= BIT3; while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = 0x00; //Receive initiated by a dummy TX write??? while (!(UCB1IFG & UCRXIFG)); //Comment this - Harsha?? _NOP(); _NOP(); *pbuf = UCB0RXBUF; pbuf++; lenght--; UCB0CTL0 |= UCCKPH; }//end of while TRF_SS_HIGH(); //Stop SPI Mode #endif } //end of SPI Mode } /* ReadSingle */
/* ======================================================================================================================= Function writes only one register or a multiple number ; of registers with specified addresses ; ======================================================================================================================= */ void WriteSingle(uint8_t *pbuf, unsigned char lenght) { /*~~~~~~~~~~~~~~*/ unsigned char i; /*~~~~~~~~~~~~~~*/ if ((SPIMODE)==0) //Parallel Mode { STARTcondition(); while(lenght > 0) { *pbuf = (0x1f &*pbuf); /* register address */ /* address, write, single */ for(i = 0; i < 2; i++) { TRFWrite = *pbuf; /* send command and data */ //PortWrite(pbuf); TRF_DCLK_ON(); TRF_DCLK_OFF(); pbuf++; lenght--; } } /* while */ STOPcondition(); } //end of Parallel mode /*********************************************************/ if (SPIMODE) //SPI Mode { #ifndef SPI_BITBANG /*********************************/ /* Start of Hardware SPI Mode */ /*********************************/ TRF_SS_LOW(); //Start SPI Mode while(lenght > 0) { *pbuf = (0x1f &*pbuf); /* register address */ for(i = 0; i < 2; i++) { while (!(UCB1IFG & UCTXIFG)); // USCI_B0 TX buffer ready? UCB0TXBUF = *pbuf; // Previous data to TX, RX // while (!(UCB1IFG & UCRXIFG)); temp=UCB0RXBUF; pbuf++; lenght--; } } /* while */ TRF_SS_HIGH(); //Stop SPI Mode #endif } //end of SPI mode } /* WriteSingle */