Add power control functions (#334)

* Update MFRC522.h
Add new power control functions : 
PCD_SoftPowerDown
PCD_SoftPowerUp
This commit is contained in:
Bill2462
2017-09-10 13:58:49 +02:00
committed by Rotzbua
parent 616a9b1a69
commit 3def3ab000
3 changed files with 40 additions and 1 deletions

View File

@@ -363,6 +363,35 @@ bool MFRC522::PCD_PerformSelfTest() {
return true;
} // End PCD_PerformSelfTest()
/////////////////////////////////////////////////////////////////////////////////////
// Power control
/////////////////////////////////////////////////////////////////////////////////////
//IMPORTANT NOTE!!!!
//Calling any other function that uses CommandReg will disable soft power down mode !!!
//For more details about power control, refer to the datasheet - page 33 (8.6)
void MFRC522::PCD_SoftPowerDown(){//Note : Only soft power down mode is available throught software
byte val = PCD_ReadRegister(CommandReg); // Read state of the command register
val |= (1<<4);// set PowerDown bit ( bit 4 ) to 1
PCD_WriteRegister(CommandReg, val);//write new value to the command register
}
void MFRC522::PCD_SoftPowerUp(){
byte val = PCD_ReadRegister(CommandReg); // Read state of the command register
val &= ~(1<<4);// set PowerDown bit ( bit 4 ) to 0
PCD_WriteRegister(CommandReg, val);//write new value to the command register
// wait until PowerDown bit is cleared (this indicates end of wake up procedure)
const uint32_t timeout = (uint32_t)millis() + 500;// create timer for timeout (just in case)
while(millis()<=timeout){ // set timeout to 500 ms
val = PCD_ReadRegister(CommandReg);// Read state of the command register
if(!(val & (1<<4))){ // if powerdown bit is 0
break;// wake up procedure is finished
}
}
}
/////////////////////////////////////////////////////////////////////////////////////
// Functions for communicating with PICCs
/////////////////////////////////////////////////////////////////////////////////////

View File

@@ -359,6 +359,12 @@ public:
void PCD_SetAntennaGain(byte mask);
bool PCD_PerformSelfTest();
/////////////////////////////////////////////////////////////////////////////////////
// Power control functions
/////////////////////////////////////////////////////////////////////////////////////
void PCD_SoftPowerDown();
void PCD_SoftPowerUp();
/////////////////////////////////////////////////////////////////////////////////////
// Functions for communicating with PICCs
/////////////////////////////////////////////////////////////////////////////////////