示例#1
0
        static void Main()
        {
#if TINYCLR_V2_SC20100DEV_MIKROBUS_1
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PD3, SC20100.GpioPin.PD4);
#endif
#if TINYCLR_V2_SC20100DEV_MIKROBUS_2
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PD14, SC20100.GpioPin.PD15);
#endif
#if TINYCLR_V2_FEZDUINO
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi6, SC20100.GpioPin.PB1, SC20100.GpioPin.PA15);
#endif
#if TINYCLR_V2_FEZPORTAL
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PC13, SC20100.GpioPin.PD4);
#endif

            rfm9XDevice.RegisterDump();

            while (true)
            {
                Debug.WriteLine("Read RegOpMode (read byte)");
                Byte regOpMode1 = rfm9XDevice.RegisterReadByte(0x1);
                Debug.WriteLine($"RegOpMode 0x{regOpMode1:x2}");

                Debug.WriteLine("Set LoRa mode and sleep mode (write byte)");
                rfm9XDevice.RegisterWriteByte(0x01, 0b10000000);

                Debug.WriteLine("Read RegOpMode (read byte)");
                Byte regOpMode2 = rfm9XDevice.RegisterReadByte(0x1);
                Debug.WriteLine($"RegOpMode 0x{regOpMode2:x2}");

                Debug.WriteLine("Read the preamble (read word)");
                ushort preamble = rfm9XDevice.RegisterReadWord(0x20);
                Debug.WriteLine($"Preamble 0x{preamble:x2}");

                Debug.WriteLine("Set the preamble to 0x80 (write word)");
                rfm9XDevice.RegisterWriteWord(0x20, 0x80);

                Debug.WriteLine("Read the center frequency (read byte array)");
                byte[] frequencyReadBytes = rfm9XDevice.RegisterRead(0x06, 3);
                Debug.WriteLine($"Frequency Msb 0x{frequencyReadBytes[0]:x2} Mid 0x{frequencyReadBytes[1]:x2} Lsb 0x{frequencyReadBytes[2]:x2}");

                Debug.WriteLine("Set the center frequency to 915MHz (write byte array)");
                byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 };
                rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

                rfm9XDevice.RegisterDump();

                Thread.Sleep(30000);
            }
        }
示例#2
0
        static void Main()
        {
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(FEZ.GpioPin.D10, FEZ.GpioPin.D9);

            rfm9XDevice.RegisterDump();

            while (true)
            {
                Debug.WriteLine("Read RegOpMode (read byte)");
                Byte regOpMode1 = rfm9XDevice.RegisterReadByte(0x1);
                Debug.WriteLine($"RegOpMode 0x{regOpMode1:x2}");

                Debug.WriteLine("Set LoRa mode and sleep mode (write byte)");
                rfm9XDevice.RegisterWriteByte(0x01, 0b10000000);

                Debug.WriteLine("Read RegOpMode (read byte)");
                Byte regOpMode2 = rfm9XDevice.RegisterReadByte(0x1);
                Debug.WriteLine($"RegOpMode 0x{regOpMode2:x2}");

                Debug.WriteLine("Read the preamble (read word)");
                ushort preamble = rfm9XDevice.RegisterReadWord(0x20);
                Debug.WriteLine($"Preamble 0x{preamble:x2}");

                Debug.WriteLine("Set the preamble to 0x80 (write word)");
                rfm9XDevice.RegisterWriteWord(0x20, 0x80);

                Debug.WriteLine("Read the center frequency (read byte array)");
                byte[] frequencyReadBytes = rfm9XDevice.RegisterRead(0x06, 5);
                Debug.WriteLine($"Frequency Msb 0x{frequencyReadBytes[0]:x2} Mid 0x{frequencyReadBytes[1]:x2} Lsb 0x{frequencyReadBytes[2]:x2}");

                Debug.WriteLine("Set the center frequency to 916MHz (write byte array)");
                byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 };
                rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

                rfm9XDevice.RegisterDump();

                Thread.Sleep(30000);
            }
        }
示例#3
0
        static void Main()
        {
#if ST_STM32F429I_DISCOVERY
            int chipSelectPinNumber = PinNumber('C', 2);
            int resetPinNumber      = PinNumber('C', 2);
#endif
#if ESP32_WROOM_32_LORA_1_CHANNEL
            int chipSelectPinNumber = Gpio.IO16;
#endif
#if NETDUINO3_WIFI
            int chipSelectPinNumber = PinNumber('B', 10);
            int resetPinNumber      = PinNumber('E', 5);
#endif
#if ST_NUCLEO144_F746ZG
            int chipSelectPinNumber = PinNumber('D', 14);
            int resetPinNumber      = PinNumber('D', 15);
#endif

            Debug.WriteLine("devMobile.IoT.Rfm9x.ShieldSPI starting");

            try
            {
#if ESP32_WROOM_32_LORA_1_CHANNEL
                Configuration.SetPinFunction(nanoFramework.Hardware.Esp32.Gpio.IO12, DeviceFunction.SPI1_MISO);
                Configuration.SetPinFunction(nanoFramework.Hardware.Esp32.Gpio.IO13, DeviceFunction.SPI1_MOSI);
                Configuration.SetPinFunction(nanoFramework.Hardware.Esp32.Gpio.IO14, DeviceFunction.SPI1_CLOCK);

                Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber);
#endif
#if ST_STM32F429I_DISCOVERY || NETDUINO3_WIFI || ST_NUCLEO144_F746ZG
                Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber);
#endif
                Thread.Sleep(500);

                rfm9XDevice.RegisterDump();

                while (true)
                {
                    Debug.WriteLine("Read RegOpMode (read byte)");
                    Byte regOpMode1 = rfm9XDevice.RegisterReadByte(0x1);
                    Debug.WriteLine($"RegOpMode 0x{regOpMode1:x2}");

                    Debug.WriteLine("Set LoRa mode and sleep mode (write byte)");
                    rfm9XDevice.RegisterWriteByte(0x01, 0b10000000);

                    Debug.WriteLine("Read RegOpMode (read byte)");
                    Byte regOpMode2 = rfm9XDevice.RegisterReadByte(0x1);
                    Debug.WriteLine($"RegOpMode 0x{regOpMode2:x2}");

                    Debug.WriteLine("Read the preamble (read word)");
                    ushort preamble = rfm9XDevice.RegisterReadWord(0x20);
                    Debug.WriteLine($"Preamble 0x{preamble:x2}");

                    Debug.WriteLine("Set the preamble to 0x80 (write word)");
                    rfm9XDevice.RegisterWriteWord(0x20, 0x80);

                    Debug.WriteLine("Read the center frequency (read byte array)");
                    byte[] frequencyReadBytes = rfm9XDevice.RegisterRead(0x06, 3);
                    Debug.WriteLine($"Frequency Msb 0x{frequencyReadBytes[0]:x2} Mid 0x{frequencyReadBytes[1]:x2} Lsb 0x{frequencyReadBytes[2]:x2}");

                    Debug.WriteLine("Set the center frequency to 915MHz (write byte array)");
                    byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 };
                    rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

                    rfm9XDevice.RegisterDump();

                    Thread.Sleep(30000);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }