Initialize() public method

Initializes SPI connection and control pins
public Initialize ( DriverExpand.SPI spi, DriverExpand.OutputPort chipEnablePin, InterruptPort interruptPort ) : void
spi DriverExpand.SPI
chipEnablePin DriverExpand.OutputPort
interruptPort Microsoft.SPOT.Hardware.InterruptPort
return void
        static void Main(string[] args)
        {
            SPI SPIport = new Microsoft.SPOT.Hardware.SPI(new Microsoft.SPOT.Hardware.SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 2000, SPI.SPI_module.SPI1));
            OutputPort nCE = new OutputPort(Cpu.Pin.GPIO_Pin2, true);
            InterruptPort nINT = new InterruptPort(Cpu.Pin.GPIO_Pin4, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            NRF24L01Plus n = new NRF24L01Plus();
            n.Initialize(SPIport, nCE, nINT);

            byte[] address = n.GetAddress(AddressSlot.Zero, 5);
            Console.WriteLine("First Address: " + ByteArrayToHexString(address));

            byte[] b = new byte[] { 0x04, 0x09, 0x02, 0x03, 0x04 };
            n.SetAddress(AddressSlot.Zero, b, false);

            address = n.GetAddress(AddressSlot.Zero, 5);
            Console.WriteLine("Second Address: " + ByteArrayToHexString(address));

            nCE.Dispose();
            nINT.Dispose();
        }
示例#2
0
        public void Run()
        {
            const byte channel = 10;

            // all addresses need to have the same length
            var fezDominoAddress = Encoding.UTF8.GetBytes("DOMIN");
            var fezMiniAddress   = Encoding.UTF8.GetBytes("MINI.");
            var fezCobraAddress  = Encoding.UTF8.GetBytes("COBRA");

            // here we determine on which device the code is running on
            switch (SystemInfo.OEMString)
            {
            case "GHI Electronics, LLC":
                switch ((Fez)SystemInfo.SystemID.Model)
                {
                case Fez.Mini:
                    _myAddress      = fezMiniAddress;
                    _otherBoards    = new byte[2][];
                    _otherBoards[0] = fezDominoAddress;
                    _otherBoards[1] = fezCobraAddress;
                    break;

                case Fez.Domino:
                    _myAddress        = fezDominoAddress;
                    _otherBoards      = new byte[2][];
                    _otherBoards[0]   = fezCobraAddress;
                    _otherBoards[1]   = fezMiniAddress;
                    _variableResistor = new AnalogIn(AnalogIn.Pin.Ain0);
                    _variableResistor.SetLinearScale(0, 3300);
                    break;

                case Fez.Cobra:
                    _myAddress      = fezCobraAddress;
                    _otherBoards    = new byte[2][];
                    _otherBoards[0] = fezMiniAddress;
                    _otherBoards[1] = fezDominoAddress;
                    break;
                }
                break;
            }

            // here we attatch event listener
            _module.OnDataReceived    += OnReceive;
            _module.OnTransmitFailed  += OnSendFailure;
            _module.OnTransmitSuccess += OnSendSuccess;

            // we nned to call Initialize() and Configure() befeore we start using the module
            _module.Initialize(_spi, _chipSelectPin, _chipEnablePin, _interruptPin);
            _module.Configure(_myAddress, channel);

            // to start receiveing we need to call Enable(), call Disable() to stop/pause
            _module.Enable();

            // example of reading your own address
            var myAddress = _module.GetAddress(AddressSlot.Zero, 5);

            Debug.Print("I am " + new string(Encoding.UTF8.GetChars(myAddress)));

            _lastActivity = DateTime.MinValue;

            // Fez Domino board is the one that starts the token passing and monitors if a token was lost
            // The timer checks each 10 sec if any token has been received since last check
            // If not than it might mean that a token was lost or never send - a new is created
            // A token may be lost if a board is reseted before sending token back
            if ((Fez)SystemInfo.SystemID.Model == Fez.Domino)
            {
                _timer = new Timer(CreateToken, null, new TimeSpan(0, 0, 0, 10), new TimeSpan(0, 0, 0, 10));
            }
        }