pub fn new(spi: SPI, nss: NSS) -> Result<Self, E> {
        let mut mfrc522 = Mfrc522 { spi, nss };

        // soft reset
        mfrc522.command(Command::SoftReset)?;

        while mfrc522.read(Register::Command)? & (1 << 4) != 0 {}

        // configure timer to operate at 10 KHz.
        // f_timer = 13.56 MHz / (2 + TPrescaler + 2)
        mfrc522.write(Register::Demod, 0x4d | (1 << 4))?;
        mfrc522.write(Register::TMode, 0x0 | (1 << 7) | 0b10)?;
        mfrc522.write(Register::TPrescaler, 165)?;

        // configure timer for a 5 ms timeout
        mfrc522.write(Register::ReloadL, 50)?;

        // forces 100% ASK modulation
        // NOTE my tags don't work without this ...
        mfrc522.write(Register::TxAsk, 1 << 6)?;

        // set preset value for the CRC co-processor to 0x6363
        // in accordance to section 6.2.4 of ISO/IEC FCD 14443-3
        mfrc522.write(Register::Mode, (0x3f & (!0b11)) | 0b01)?;

        // enable the antenna
        mfrc522.write(Register::TxControl, 0x80 | 0b11)?;

        Ok(mfrc522)
    }
/// Creates a new driver from a SPI driver and a NSS pin
Creates a new driver from a SPI driver and a NSS pin
Creates a new driver from a SPI driver and a NSS pin
pub fn new(spi: SPI, nss: NSS) -> Result<Self, E> {
        let mut mfrc522 = Mfrc522 { spi, nss };
        // soft reset
        mfrc522.command(Command::SoftReset)?;
        while mfrc522.read(Register::Command)? & (1 << 4) != 0 {}
        // configure timer to operate at 10 KHz.
        // f_timer = 13.56 MHz / (2 + TPrescaler + 2)
        mfrc522.write(Register::Demod, 0x4d | (1 << 4))?;
        mfrc522.write(Register::TMode, 0x0 | (1 << 7) | 0b10)?;
        mfrc522.write(Register::TPrescaler, 165)?;
        // configure timer for a 5 ms timeout
        mfrc522.write(Register::ReloadL, 50)?;
        // forces 100% ASK modulation
        // NOTE my tags don't work without this ...
        mfrc522.write(Register::TxAsk, 1 << 6)?;
        // set preset value for the CRC co-processor to 0x6363
        // in accordance to section 6.2.4 of ISO/IEC FCD 14443-3
        mfrc522.write(Register::Mode, (0x3f & (!0b11)) | 0b01)?;
        // enable the antenna
        mfrc522.write(Register::TxControl, 0x80 | 0b11)?;
        Ok(mfrc522)
    }
pub fn new ( spi : SPI , nss : NSS ) -> Result < Self , E > { let mut mfrc522 = Mfrc522 { spi , nss } ; // soft reset mfrc522 . command ( Command :: SoftReset ) ? ; while mfrc522 . read ( Register :: Command ) ? & ( 1 << 4 ) != 0 { } // configure timer to operate at 10 KHz. // f_timer = 13.56 MHz / (2 + TPrescaler + 2) mfrc522 . write ( Register :: Demod , 0x4d | ( 1 << 4 ) ) ? ; mfrc522 . write ( Register :: TMode , 0x0 | ( 1 << 7 ) | 0b10 ) ? ; mfrc522 . write ( Register :: TPrescaler , 165 ) ? ; // configure timer for a 5 ms timeout mfrc522 . write ( Register :: ReloadL , 50 ) ? ; // forces 100% ASK modulation // NOTE my tags don't work without this ... mfrc522 . write ( Register :: TxAsk , 1 << 6 ) ? ; // set preset value for the CRC co-processor to 0x6363 // in accordance to section 6.2.4 of ISO/IEC FCD 14443-3 mfrc522 . write ( Register :: Mode , ( 0x3f & ( ! 0b11 ) ) | 0b01 ) ? ; // enable the antenna mfrc522 . write ( Register :: TxControl , 0x80 | 0b11 ) ? ; Ok ( mfrc522 ) }
Creates a new driver from a SPI driver and a NSS pin
Creates a new driver from a SPI driver and a NSS pin
spi
SPI
nss
NSS