Autoformat example MinimalInterrupt.ino

- auto format from arduino ide
- unsigned char ->  byte
This commit is contained in:
Rotzbua
2016-10-14 15:08:49 +02:00
parent c6a341f7a3
commit 82f2074e40

View File

@@ -31,14 +31,14 @@
#define RST_PIN 9 // Configurable, see typical pin layout above #define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 3 // Configurable, see typical pin layout above #define SS_PIN 3 // Configurable, see typical pin layout above
#define IRQ_PIN 2 #define IRQ_PIN 2 // Configurable, depends on hardware
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
MFRC522::MIFARE_Key key; MFRC522::MIFARE_Key key;
volatile boolean bNewInt = false; volatile boolean bNewInt = false;
unsigned char regVal = 0x7F; byte regVal = 0x7F;
void activateRec(MFRC522 mfrc522); void activateRec(MFRC522 mfrc522);
void clearInt(MFRC522 mfrc522); void clearInt(MFRC522 mfrc522);
@@ -53,7 +53,7 @@ void setup() {
mfrc522.PCD_Init(); // Init MFRC522 card mfrc522.PCD_Init(); // Init MFRC522 card
/* read and printout the MFRC522 version (valid values 0x91 & 0x92)*/ /* read and printout the MFRC522 version (valid values 0x91 & 0x92)*/
Serial.print("Ver: 0x"); Serial.print(F("Ver: 0x"));
byte readReg = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); byte readReg = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.println(readReg, HEX); Serial.println(readReg, HEX);
@@ -65,28 +65,27 @@ void setup() {
* For test purposes propagate the IdleIrq and loAlert * For test purposes propagate the IdleIrq and loAlert
*/ */
regVal = 0xA0; //rx irq regVal = 0xA0; //rx irq
mfrc522.PCD_WriteRegister(mfrc522.ComIEnReg,regVal); mfrc522.PCD_WriteRegister(mfrc522.ComIEnReg, regVal);
bNewInt = false; //interrupt flag bNewInt = false; //interrupt flag
/*Activate the interrupt*/ /*Activate the interrupt*/
attachInterrupt(digitalPinToInterrupt(IRQ_PIN), readCard, FALLING); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), readCard, FALLING);
do{ //clear a spourious interrupt at start do { //clear a spourious interrupt at start
; ;
}while(!bNewInt); } while (!bNewInt);
bNewInt = false; bNewInt = false;
Serial.println("End setup"); Serial.println(F("End setup"));
} }
/** /**
* Main loop. * Main loop.
*/ */
void loop() { void loop() {
if (bNewInt) { //new read interrupt
if(bNewInt){ //new read interrupt Serial.print(F("Interrupt. "));
Serial.print("Interrupt. ");
mfrc522.PICC_ReadCardSerial(); //read the tag data mfrc522.PICC_ReadCardSerial(); //read the tag data
// Show some details of the PICC (that is: the tag/card) // Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:")); Serial.print(F("Card UID:"));
@@ -98,8 +97,8 @@ void loop() {
bNewInt = false; bNewInt = false;
} }
// The receiving block needs regular retriggering (tell the tag it should transmit??) // The receiving block needs regular retriggering (tell the tag it should transmit??)
// (mfrc522.PCD_WriteRegister(mfrc522.FIFODataReg,mfrc522.PICC_CMD_REQA);) // (mfrc522.PCD_WriteRegister(mfrc522.FIFODataReg,mfrc522.PICC_CMD_REQA);)
activateRec(mfrc522); activateRec(mfrc522);
delay(100); delay(100);
} //loop() } //loop()
@@ -116,24 +115,23 @@ void dump_byte_array(byte *buffer, byte bufferSize) {
/** /**
* MFRC522 interrupt serving routine * MFRC522 interrupt serving routine
*/ */
void readCard(){ void readCard() {
bNewInt = true; bNewInt = true;
} }
/* /*
* The function sending to the MFRC522 the needed commands to activate the reception * The function sending to the MFRC522 the needed commands to activate the reception
*/ */
void activateRec(MFRC522 mfrc522){ void activateRec(MFRC522 mfrc522) {
mfrc522.PCD_WriteRegister(mfrc522.FIFODataReg,mfrc522.PICC_CMD_REQA); mfrc522.PCD_WriteRegister(mfrc522.FIFODataReg, mfrc522.PICC_CMD_REQA);
mfrc522.PCD_WriteRegister(mfrc522.CommandReg,mfrc522.PCD_Transceive); mfrc522.PCD_WriteRegister(mfrc522.CommandReg, mfrc522.PCD_Transceive);
mfrc522.PCD_WriteRegister(mfrc522.BitFramingReg, 0x87); mfrc522.PCD_WriteRegister(mfrc522.BitFramingReg, 0x87);
} }
/* /*
* The function to clear the pending interrupt bits after interrupt serving routine * The function to clear the pending interrupt bits after interrupt serving routine
*/ */
void clearInt(MFRC522 mfrc522){ void clearInt(MFRC522 mfrc522) {
mfrc522.PCD_WriteRegister(mfrc522.ComIrqReg,0x7F); mfrc522.PCD_WriteRegister(mfrc522.ComIrqReg, 0x7F);
} }