Get() public static méthode

public static Get ( byte address ) : byte
address byte
Résultat byte
Exemple #1
0
        /// <summary>
        /// Configure the module basic settings. Module needs to be initiaized.
        /// </summary>
        /// <param name="address">RF address (3-5 bytes). The width of this address determins the width of all addresses used for sending/receiving.</param>
        /// <param name="channel">RF channel (0-127)</param>
        public void Configure(byte[] address, byte channel)
        {
            CheckIsInitialized();
            AddressWidth.Check(address);

            // Set radio channel
            Execute(Commands.W_REGISTER, Registers.RF_CH,
                    new[]
            {
                (byte)(channel & 0x7F)              // channel is 7 bits
            });

            // Enable dynamic payload length
            Execute(Commands.W_REGISTER, Registers.FEATURE,
                    new[]
            {
                (byte)(1 << Bits.EN_DPL)
            });

            // Set auto-ack
            Execute(Commands.W_REGISTER, Registers.EN_AA,
                    new[] { (byte)(0x01) });

            // Set RX-addr EN_RXADDR
            Execute(Commands.W_REGISTER, Registers.EN_RXADDR,
                    new[] { (byte)(0x01) });

            // Set dynamic payload length for pipes
            Execute(Commands.W_REGISTER, Registers.DYNPD,
                    new[]
            {
                (byte)(1 << Bits.DPL_P0 |
                       1 << Bits.DPL_P1)
            });

            // Flush RX FIFO
            Execute(Commands.FLUSH_RX, 0x00, new byte[0]);

            // Flush TX FIFO
            Execute(Commands.FLUSH_TX, 0x00, new byte[0]);

            // Clear IRQ Masks
            Execute(Commands.W_REGISTER, Registers.STATUS,
                    new[]
            {
                (byte)(1 << Bits.MASK_RX_DR |
                       1 << Bits.MASK_TX_DS |
                       1 << Bits.MAX_RT)
            });

            // Set default address
            Execute(Commands.W_REGISTER, Registers.SETUP_AW,
                    new[]
            {
                AddressWidth.Get(address)
            });

            // Set module address
            SetAddress(AddressSlot.Zero, address, true);
            //Execute(Commands.W_REGISTER, (byte)AddressSlot.Zero, address); //No cal pq també s'executa quan es posa en receive mode al final de configure
            _slot1Address = _def_rx_addr_p1;
            _slot2Address = _def_rx_addr_p2;
            _slot3Address = _def_rx_addr_p3;
            _slot4Address = _def_rx_addr_p4;
            _slot5Address = _def_rx_addr_p5;

            // Set retransmission values
            Execute(Commands.W_REGISTER, Registers.SETUP_RETR,
                    new[]
            {
                (byte)(0x01 << Bits.ARD |
                       0x00 << Bits.ARC)
            });

            // Set RF Setup
            Execute(Commands.W_REGISTER, Registers.RF_SETUP,
                    new[]
            {
                (byte)(0xBF & 0x05)              // bit 6 is reserved
            });



            // Setup, CRC enabled, Power Up, PRX
            SetReceiveMode();
        }
Exemple #2
0
        /// <summary>
        /// Configure the module basic settings. Module needs to be initiaized.
        /// </summary>
        /// <param name="address">RF address (3-5 bytes). The width of this address determins the width of all addresses used for sending/receiving.</param>
        /// <param name="channel">RF channel (0-127)</param>
        /// <param name="dataRate">Data Rate to use</param>
        public void Configure(byte[] address, byte channel, NRFDataRate dataRate)
        {
            CheckIsInitialized();
            AddressWidth.Check(address);

            // Set radio channel
            Execute(Commands.W_REGISTER, Registers.RF_CH,
                    new[]
            {
                (byte)(channel & 0x7F)              // channel is 7 bits
            });

            // Set Data rate
            var regValue = Execute(Commands.R_REGISTER, Registers.RF_SETUP, new byte[1])[1];

            switch (dataRate)
            {
            case NRFDataRate.DR1Mbps:
                regValue &= (byte)~(1 << Bits.RF_DR_LOW);                   // 0
                regValue &= (byte)~(1 << Bits.RF_DR_HIGH);                  // 0
                break;

            case NRFDataRate.DR2Mbps:
                regValue &= (byte)~(1 << Bits.RF_DR_LOW);       // 0
                regValue |= (byte)(1 << Bits.RF_DR_HIGH);       // 1
                break;

            case NRFDataRate.DR250kbps:
                regValue |= (byte)(1 << Bits.RF_DR_LOW);        // 1
                regValue &= (byte)~(1 << Bits.RF_DR_HIGH);      // 0
                break;

            default:
                throw new ArgumentOutOfRangeException("dataRate");
            }

            Execute(Commands.W_REGISTER, Registers.RF_SETUP, new[] { regValue });

            // Enable dynamic payload length
            Execute(Commands.W_REGISTER, Registers.FEATURE,
                    new[]
            {
                (byte)(1 << Bits.EN_DPL)
            });

            // Set auto-ack
            Execute(Commands.W_REGISTER, Registers.EN_AA,
                    new[]
            {
                (byte)(1 << Bits.ENAA_P0 |
                       1 << Bits.ENAA_P1)
            });

            // Set dynamic payload length for pipes
            Execute(Commands.W_REGISTER, Registers.DYNPD,
                    new[]
            {
                (byte)(1 << Bits.DPL_P0 |
                       1 << Bits.DPL_P1)
            });

            // Flush RX FIFO
            Execute(Commands.FLUSH_RX, 0x00, new byte[0]);

            // Flush TX FIFO
            Execute(Commands.FLUSH_TX, 0x00, new byte[0]);

            // Clear IRQ Masks
            Execute(Commands.W_REGISTER, Registers.STATUS,
                    new[]
            {
                (byte)(1 << Bits.MASK_RX_DR |
                       1 << Bits.MASK_TX_DS |
                       1 << Bits.MAX_RT)
            });

            // Set default address
            Execute(Commands.W_REGISTER, Registers.SETUP_AW,
                    new[]
            {
                AddressWidth.Get(address)
            });

            // Set module address
            _slot0Address = address;
            Execute(Commands.W_REGISTER, (byte)AddressSlot.Zero, address);

            // Set retransmission values
            Execute(Commands.W_REGISTER, Registers.SETUP_RETR,
                    new[]
            {
                (byte)(0x0F << Bits.ARD |
                       0x0F << Bits.ARC)
            });

            // Setup, CRC enabled, Power Up, PRX
            SetReceiveMode();
        }