diff --git a/README.md b/README.md index 0550f54..e6c312e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,62 @@ CLK -> 18 (D5) MISO -> 19 (D6) ``` +### RFID Reader + +``` + +``` + +#### Registers + +``` +Writing 0x7F to the "ComIEnReg" means the following: + + Bit 7: IRqInv=0 - Interrupts are active high + Bit 6: TxIEn=1 - Transmitter interrupt is enabled + Bit 5: RxIEn=1 - Receive interrupt is enabled + Bit 4: IdleIEn=1 - Idle interrupt is enabled + Bit 3: HiAlertIEn=1 - "High Alert" interrupt is enabled + Bit 2: LoAlertIEn=1 - "Low Alert" interrupt is enabled + Bit 1: ErrIEn=1 - Error interrupt is enabled + Bit 0: TimerIEn=1 - Timer interrupt is enabled + +The bits in the register "ComIrqReg" have the following meaning: + + Bit 7: Set1 - when written as 1, a bit value of 1 in bits 6-0 of the byte written set the corresponding register bit; when written as 0, bits 6-0 clear the corresponding register bit + Bit 6: TxIRq - Set when the last bit of Tx data has been sent + Bit 5: RxIRq - Set when the receiver detects the end of a valid data stream + Bit 4: IdleIRq - Set when the CommandReg changes the command field to the idle command + Bit 3: HiAlertIRq - Set when the Status1 register HiAlert bit is set + Bit 2: LoAlertIRq - Set when the Status1 register LoAlert bit is set + Bit 1: ErrIRq - Set when any bit in ErrorReg gets set + Bit 0: TimerIRq - Set when the TCounterValReg decrements to zero + +Writing 0x14 to the "DivIEnReg" has the following meaning: + + Bit 7: IRQPushPull=0 - IRQ is an open-drain output pin + Bit 6: reserved=0 - no known effect + Bit 5: reserved=0 - effect unknown + Bit 4: MfinActEn=1 - Allow the MFIN active interrupt request to trigger IRQ + Bit 3: reserved=0 - boundedly undefined + Bit 2: CRCIEn=1 - Permit the "DivIrqReg" bit CRCIRq to trigger IRQ + Bit 1: reserved=0 - do not set to 1 on pain of nothing + Bit 0: reserved=0 - has no purpose other than to confuse + +The register "DivIrqReg" corresponds to "DivIrqEn", and has the following bit definitions: + + Bit 7: Set2 - when written as 1, a bit value of 1 in bits 6-0 of the byte written set the corresponding register bit; when written as 0, bits 6-0 clear the corresponding register bit + Bit 6: reserved - don't ask + Bit 5: reserved - don't tell + Bit 4: MfinActIRq - MFIN is active + Bit 3: reserved - just leave it at zero and back away slowly + Bit 2: CRCIRq - when 1, the CalcCRC command is active and all data is processed + Bit 1: reserved - nothing to see here + Bit 0: reserved - are you feeling lucky, punk? +``` + + + ## Buttons ``` diff --git a/src/main.cpp b/src/main.cpp index ee15673..b4aca4f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,7 @@ File mp3File; Audio audio; -uint volume = 18; +uint volume = 12; AsyncWebServer server(80); DNSServer dns; @@ -95,8 +95,10 @@ void playNextMp3() String mp3File = currentNode->getCurrentPlayingFilePath(); Serial.println(mp3File.c_str()); deactivateRFID(); + activateSD(); audio.connecttoSD(mp3File.c_str()); activateRFID(); + deactivateSD(); blockState = false; } @@ -199,7 +201,7 @@ void readRFID() { } void clearInt(MFRC522 mfrc522) { - mfrc522.PCD_WriteRegister(mfrc522.ComIrqReg, 0x7F); + mfrc522.PCD_WriteRegister(mfrc522.ComIrqReg, 0x60); } void IRAM_ATTR rfid_interrupt() { @@ -260,13 +262,15 @@ void setup() * Allow the ... irq to be propagated to the IRQ pin * For test purposes propagate the IdleIrq and loAlert */ - //rfid.PCD_WriteRegister(rfid.ComIEnReg, 0xA0); - attachInterrupt(IRQ_RFID, rfid_interrupt, FALLING); - - do { //clear a spourious interrupt at start + rfid.PCD_WriteRegister(rfid.ComIEnReg, 0x60); + attachInterrupt(IRQ_RFID, rfid_interrupt, RISING); + //clear a spourious interrupt at start + /* + do { ; } while (!newRfidInt); newRfidInt = false; //interrupt flag + */ } else { Serial.println("RFID Self Test failed!"); } @@ -274,6 +278,7 @@ void setup() audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); audio.setVolume(volume); // 0...21 + Serial.println("Audio initialized."); @@ -311,22 +316,26 @@ void setup() void loop() { - deactivateRFID(); + activateSD(); audio.loop(); + deactivateSD(); activateRFID(); + /* + if(rfid.PICC_IsNewCardPresent()) { + stop(); + readRFID(); + }*/ if (newRfidInt) { + Serial.println("Interrupt."); - if(rfid.PICC_IsNewCardPresent()) { + if(rfid.PICC_IsNewCardPresent()) { + stop(); readRFID(); - stop(); } - - - clearInt(rfid); + //clearInt(rfid); newRfidInt = false; - }