Merge pull request #47 from mdxs/exp_range

Adding AttennaOff and get/set of AntennaGain
This commit is contained in:
Miki Balboa
2014-11-10 09:07:29 -06:00
3 changed files with 64 additions and 1 deletions

View File

@@ -242,6 +242,36 @@ void MFRC522::PCD_AntennaOn() {
} }
} // End PCD_AntennaOn() } // End PCD_AntennaOn()
/**
* Turns the antenna off by disabling pins TX1 and TX2.
*/
void MFRC522::PCD_AntennaOff() {
PCD_ClearRegisterBitMask(RFCfgReg, 0x03);
} // End PCD_AntennaOff()
/**
* Get the current MFRC522 Receiver Gain (RxGain[2:0]) value.
* See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf
* NOTE: Return value scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits.
*
* @return Value of the RxGain, scrubbed to the 3 bits used.
*/
byte MFRC522::PCD_GetAntennaGain() {
return PCD_ReadRegister(RFCfgReg) & (0x07<<4);
} // End PCD_GetAntennaGain()
/**
* Set the MFRC522 Receiver Gain (RxGain) to value specified by given mask.
* See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf
* NOTE: Given mask is scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits.
*/
void MFRC522::PCD_SetAntennaGain(byte mask) {
if (PCD_GetAntennaGain() != mask) { // only bother if there is a change
PCD_ClearRegisterBitMask(RFCfgReg, (0x07<<4)); // clear needed to allow 000 pattern
PCD_SetRegisterBitMask(RFCfgReg, mask & (0x07<<4)); // only set RxGain[2:0] bits
}
} // End PCD_SetAntennaGain()
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// Functions for communicating with PICCs // Functions for communicating with PICCs
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////

View File

@@ -169,6 +169,22 @@ public:
PCD_SoftReset = 0x0F // resets the MFRC522 PCD_SoftReset = 0x0F // resets the MFRC522
}; };
// MFRC522 RxGain[2:0] masks, defines the receiver's signal voltage gain factor (on the PCD).
// Described in 9.3.3.6 / table 98 of the datasheet at http://www.nxp.com/documents/data_sheet/MFRC522.pdf
enum PCD_RxGain {
RxGain_18dB = 0x00 << 4, // 000b - 18 dB, minimum
RxGain_23dB = 0x01 << 4, // 001b - 23 dB
RxGain_18dB_2 = 0x02 << 4, // 010b - 18 dB, it seems 010b is a duplicate for 000b
RxGain_23dB_2 = 0x03 << 4, // 011b - 23 dB, it seems 011b is a duplicate for 001b
RxGain_33dB = 0x04 << 4, // 100b - 33 dB, average, and typical default
RxGain_38dB = 0x05 << 4, // 101b - 38 dB
RxGain_43dB = 0x06 << 4, // 110b - 43 dB
RxGain_48dB = 0x07 << 4, // 111b - 48 dB, maximum
RxGain_min = 0x00 << 4, // 000b - 18 dB, minimum, convenience for RxGain_18dB
RxGain_avg = 0x04 << 4, // 100b - 33 dB, average, convenience for RxGain_33dB
RxGain_max = 0x07 << 4 // 111b - 48 dB, maximum, convenience for RxGain_48dB
};
// Commands sent to the PICC. // Commands sent to the PICC.
enum PICC_Command { enum PICC_Command {
// The commands used by the PCD to manage communication with several PICCs (ISO 14443-3, Type A, section 6.4) // The commands used by the PCD to manage communication with several PICCs (ISO 14443-3, Type A, section 6.4)
@@ -270,6 +286,9 @@ public:
void PCD_Init(); void PCD_Init();
void PCD_Reset(); void PCD_Reset();
void PCD_AntennaOn(); void PCD_AntennaOn();
void PCD_AntennaOff();
byte PCD_GetAntennaGain();
void PCD_SetAntennaGain(byte mask);
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// Functions for communicating with PICCs // Functions for communicating with PICCs

View File

@@ -8,6 +8,7 @@
MFRC522 KEYWORD1 MFRC522 KEYWORD1
PCD_Register KEYWORD1 PCD_Register KEYWORD1
PCD_Command KEYWORD1 PCD_Command KEYWORD1
PCD_RxGain KEYWORD1
PICC_Command KEYWORD1 PICC_Command KEYWORD1
MIFARE_Misc KEYWORD1 MIFARE_Misc KEYWORD1
PICC_Type KEYWORD1 PICC_Type KEYWORD1
@@ -30,6 +31,9 @@ PCD_CalculateCRC KEYWORD2
PCD_Init KEYWORD2 PCD_Init KEYWORD2
PCD_Reset KEYWORD2 PCD_Reset KEYWORD2
PCD_AntennaOn KEYWORD2 PCD_AntennaOn KEYWORD2
PCD_AntennaOff KEYWORD2
PCD_GetAntennaGain KEYWORD2
PCD_SetAntennaGain KEYWORD2
PCD_TransceiveData KEYWORD2 PCD_TransceiveData KEYWORD2
PCD_CommunicateWithPICC KEYWORD2 PCD_CommunicateWithPICC KEYWORD2
PICC_RequestA KEYWORD2 PICC_RequestA KEYWORD2
@@ -120,6 +124,17 @@ PCD_Receive LITERAL1
PCD_Transceive LITERAL1 PCD_Transceive LITERAL1
PCD_MFAuthent LITERAL1 PCD_MFAuthent LITERAL1
PCD_SoftReset LITERAL1 PCD_SoftReset LITERAL1
RxGain_18dB LITERAL1
RxGain_23dB LITERAL1
RxGain_18dB_2 LITERAL1
RxGain_23dB_2 LITERAL1
RxGain_33dB LITERAL1
RxGain_38dB LITERAL1
RxGain_43dB LITERAL1
RxGain_48dB LITERAL1
RxGain_min LITERAL1
RxGain_avg LITERAL1
RxGain_max LITERAL1
PICC_CMD_REQA LITERAL1 PICC_CMD_REQA LITERAL1
PICC_CMD_WUPA LITERAL1 PICC_CMD_WUPA LITERAL1
PICC_CMD_CT LITERAL1 PICC_CMD_CT LITERAL1
@@ -158,4 +173,3 @@ STATUS_INVALID LITERAL1
STATUS_CRC_WRONG LITERAL1 STATUS_CRC_WRONG LITERAL1
STATUS_MIFARE_NACK LITERAL1 STATUS_MIFARE_NACK LITERAL1
FIFO_SIZE LITERAL1 FIFO_SIZE LITERAL1