/// <summary> /// Initializes a new instance of the <see cref="RFIDClick"/> class. /// </summary> /// <param name="socket">The socket on which the RFID Click board is plugged on MikroBus.Net board</param> /// <exception cref="DeviceInitialisationException">RFID module not detected</exception> public RFIDClick(Hardware.Socket socket) { _socket = socket; _rBuffer = new Byte[261]; _tmpBuffer = new byte[260]; GpioPin _rst = GpioController.GetDefault().OpenPin(socket.Rst); _rst.SetDriveMode(GpioPinDriveMode.Output); GpioPin _an = GpioController.GetDefault().OpenPin(socket.AnPin); _an.SetDriveMode(GpioPinDriveMode.Output); _irqIn = GpioController.GetDefault().OpenPin(socket.PwmPin); _irqIn.SetDriveMode(GpioPinDriveMode.Output); // Set SPI mode on the chip _rst.Write(GpioPinValue.High); _an.Write(GpioPinValue.Low); _irqIn.Write(GpioPinValue.High); // Now that the chip is in SPI mode, we can create the SPI configuration and talk to the module _rfid = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings() { ChipSelectType = SpiChipSelectType.Gpio, ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs), Mode = SpiMode.Mode0, ClockFrequency = 2000000 }); _rfid.Write(new byte[] { 0x01, 0x01 }); Thread.Sleep(100); ToggleIRQ_IN(); Thread.Sleep(100); _dataReady = GpioController.GetDefault().OpenPin(socket.Int); _dataReady.SetDriveMode(GpioPinDriveMode.InputPullUp); //_dataReady.ValueChangedEdge = GpioPinEdge.FallingEdge; _dataReady.ValueChanged += DataReady_ValueChanged; if (Echo() != 0x55) { //throw new DeviceInitialisationException("RFID device not found"); } IndexMod_Gain(); AutoFDet(); _protocol = RFIDProtocol.NONE; // Protocol can't be set before calibration has been done _calibrationDone = false; _powerMode = PowerModes.On; _lastTag = ""; }
/// <summary> /// Initializes a new instance of the <see cref="RFIDClick"/> class. /// </summary> /// <param name="socket">The socket on which the RFID Click board is plugged on MikroBus.Net board</param> /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception> /// <exception cref="MBN.Exceptions.DeviceInitialisationException">RFID module not detected</exception> public RFIDClick(Hardware.Socket socket) { Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.An, socket.Rst, socket.Int); _rBuffer = new Byte[260]; // Set SPI mode on the chip new OutputPort(socket.Rst, true); new OutputPort(socket.An, false); IRQ_IN = new OutputPort(socket.Pwm, true); Thread.Sleep(1); ToggleIRQ_IN(); // Now that the chip is in SPI mode, we can create the NETMF configuration and talk to the module _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, false, true, 2000, socket.SpiModule); if (Hardware.SPIBus == null) { Hardware.SPIBus = new SPI(_spiConfig); } _dataReady = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow); _dataReady.OnInterrupt += DataReady_OnInterrupt; _dataReady.EnableInterrupt(); if (Echo() != 0x55) { throw new DeviceInitialisationException("RFID device not found"); } IndexMod_Gain(); AutoFDet(); _protocol = RFIDProtocol.NONE; // Protocol can't be set before calibration has been done _calibrationDone = false; _powerMode = PowerModes.On; _lastTag = ""; }