static void Main()
        {
#if TINYCLR_V2_SC20100DEV_MIKROBUS_1
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PD3, SC20100.GpioPin.PD4, SC20100.GpioPin.PC5);
#endif
#if TINYCLR_V2_SC20100DEV_MIKROBUS_2
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PD14, SC20100.GpioPin.PD15, SC20100.GpioPin.PA8);
#endif
#if TINYCLR_V2_FEZDUINO
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi6, SC20100.GpioPin.PB1, SC20100.GpioPin.PA15, SC20100.GpioPin.PA1);
#endif
#if TINYCLR_V2_FEZPORTAL
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SC20100.SpiBus.Spi3, SC20100.GpioPin.PC13, SC20100.GpioPin.PD4, SC20100.GpioPin.PC2);
#endif
            int sendCount = 0;

            // Put device into LoRa + Sleep mode
            rfm9XDevice.RegisterWriteByte(0x01, 0b10000000); // RegOpMode

            // Set the frequency to 915MHz
            byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 }; // RegFrMsb, RegFrMid, RegFrLsb
            rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

            rfm9XDevice.RegisterWriteByte(0x0F, 0x0); // RegFifoRxBaseAddress

            // More power PA Boost
            rfm9XDevice.RegisterWriteByte(0x09, 0b10000000); // RegPaConfig

            rfm9XDevice.RegisterWriteByte(0x01, 0b10000101); // RegOpMode set LoRa & RxContinuous

            while (true)
            {
                rfm9XDevice.RegisterWriteByte(0x0E, 0x0); // RegFifoTxBaseAddress

                // Set the Register Fifo address pointer
                rfm9XDevice.RegisterWriteByte(0x0D, 0x0); // RegFifoAddrPtr

                string messageText = $"Hello LoRa {sendCount += 1}!";

                // load the message into the fifo
                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                rfm9XDevice.RegisterWrite(0x0, messageBytes); // RegFifo

                // Set the length of the message in the fifo
                rfm9XDevice.RegisterWriteByte(0x22, (byte)messageBytes.Length); // RegPayloadLength
                rfm9XDevice.RegisterWriteByte(0x40, 0b01000000);                // RegDioMapping1 0b00000000 DI0 RxReady & TxReady
                rfm9XDevice.RegisterWriteByte(0x01, 0b10000011);                // RegOpMode

                Debug.WriteLine($"Sending {messageBytes.Length} bytes message {messageText}");

                Thread.Sleep(10000);
            }
        }
Exemple #2
0
        static void Main()
        {
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(FEZ.GpioPin.D10, FEZ.GpioPin.D9, FEZ.GpioPin.D2);
            int         sendCount   = 0;

            // Put device into LoRa + Sleep mode
            rfm9XDevice.RegisterWriteByte(0x01, 0b10000000); // RegOpMode

            // Set the frequency to 915MHz
            byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 }; // RegFrMsb, RegFrMid, RegFrLsb
            rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

            rfm9XDevice.RegisterWriteByte(0x0F, 0x0); // RegFifoRxBaseAddress

            // More power PA Boost
            rfm9XDevice.RegisterWriteByte(0x09, 0b10000000); // RegPaConfig

            rfm9XDevice.RegisterWriteByte(0x01, 0b10000101); // RegOpMode set LoRa & RxContinuous

            while (true)
            {
                rfm9XDevice.RegisterWriteByte(0x0E, 0x0); // RegFifoTxBaseAddress

                // Set the Register Fifo address pointer
                rfm9XDevice.RegisterWriteByte(0x0D, 0x0); // RegFifoAddrPtr

                string messageText = $"Hello LoRa {sendCount += 1}!";

                // load the message into the fifo
                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                rfm9XDevice.RegisterWrite(0x0, messageBytes); // RegFifo

                // Set the length of the message in the fifo
                rfm9XDevice.RegisterWriteByte(0x22, (byte)messageBytes.Length); // RegPayloadLength
                rfm9XDevice.RegisterWriteByte(0x40, 0b01000000);                // RegDioMapping1 0b00000000 DI0 RxReady & TxReady
                rfm9XDevice.RegisterWriteByte(0x01, 0b10000011);                // RegOpMode

                Debug.WriteLine($"Sending {messageBytes.Length} bytes message {messageText}");

                Thread.Sleep(10000);
            }
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Put device into LoRa + Sleep mode
            rfm9XDevice.RegisterWriteByte(0x01, 0b10000000);             // RegOpMode

            // Set the frequency to 915MHz
            byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 };             // RegFrMsb, RegFrMid, RegFrLsb
            rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

            rfm9XDevice.RegisterWriteByte(0x0F, 0x0);             // RegFifoRxBaseAddress

            // More power PA Boost
            rfm9XDevice.RegisterWriteByte(0x09, 0b10000000);             // RegPaConfig

            rfm9XDevice.RegisterWriteByte(0x01, 0b10000101);             // RegOpMode set LoRa & RxContinuous


            while (true)
            {
                rfm9XDevice.RegisterWriteByte(0x0E, 0x0);                 // RegFifoTxBaseAddress

                // Set the Register Fifo address pointer
                rfm9XDevice.RegisterWriteByte(0x0D, 0x0);                 // RegFifoAddrPtr

                string messageText = "W10 IoT Core LoRa! " + MessageCount.ToString();
                MessageCount -= 1;

                // load the message into the fifo
                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                foreach (byte b in messageBytes)
                {
                    rfm9XDevice.RegisterWriteByte(0x0, b);                     // RegFifo
                }

                // Set the length of the message in the fifo
                rfm9XDevice.RegisterWriteByte(0x22, (byte)messageBytes.Length);  // RegPayloadLength
                rfm9XDevice.RegisterWriteByte(0x40, 0b01000000);                 // RegDioMapping1 0b00000000 DI0 RxReady & TxReady
                rfm9XDevice.RegisterWriteByte(0x01, 0b10000011);                 // RegOpMode


                Debug.WriteLine("Sending {0} bytes message {1}", messageBytes.Length, messageText);

                Task.Delay(10000).Wait();
            }
        }
Exemple #4
0
        static void Main()
        {
            int SendCount = 0;

#if ST_STM32F429I_DISCOVERY
            int chipSelectPinNumber = PinNumber('C', 2);
            int resetPinNumber      = PinNumber('C', 3);
            int interruptPinNumber  = PinNumber('A', 4);
#endif
#if ESP32_WROOM_32_LORA_1_CHANNEL
            int chipSelectPinNumber = Gpio.IO16;
            int interruptPinNumber  = Gpio.IO26;
#endif
#if NETDUINO3_WIFI
            int chipSelectPinNumber = PinNumber('B', 10);
            int resetPinNumber      = PinNumber('E', 5);
            int interruptPinNumber  = PinNumber('A', 3);
#endif

            try
            {
#if ESP32_WROOM_32_LORA_1_CHANNEL
                Configuration.SetPinFunction(Gpio.IO12, DeviceFunction.SPI1_MISO);
                Configuration.SetPinFunction(Gpio.IO13, DeviceFunction.SPI1_MOSI);
                Configuration.SetPinFunction(Gpio.IO14, DeviceFunction.SPI1_CLOCK);
                Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, interruptPinNumber);
#endif
#if ST_STM32F429I_DISCOVERY || NETDUINO3_WIFI
                Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber, interruptPinNumber);
#endif
                Thread.Sleep(500);

                // Put device into LoRa + Sleep mode
                rfm9XDevice.RegisterWriteByte(0x01, 0b10000000); // RegOpMode

                // Set the frequency to 915MHz
                byte[] frequencyWriteBytes = { 0xE4, 0xC0, 0x00 }; // RegFrMsb, RegFrMid, RegFrLsb
                rfm9XDevice.RegisterWrite(0x06, frequencyWriteBytes);

                // More power PA Boost
                rfm9XDevice.RegisterWriteByte(0x09, 0b10000000); // RegPaConfig

                rfm9XDevice.RegisterWriteByte(0x01, 0b10000101); // RegOpMode set LoRa & RxContinuous

                while (true)
                {
                    // Set the Register Fifo address pointer
                    rfm9XDevice.RegisterWriteByte(0x0E, 0x00); // RegFifoTxBaseAddress

                    // Set the Register Fifo address pointer
                    rfm9XDevice.RegisterWriteByte(0x0D, 0x0); // RegFifoAddrPtr

                    string messageText = $"Hello LoRa {SendCount += 1}!";

                    // load the message into the fifo
                    byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                    rfm9XDevice.RegisterWrite(0x0, messageBytes); // RegFifo

                    // Set the length of the message in the fifo
                    rfm9XDevice.RegisterWriteByte(0x22, (byte)messageBytes.Length); // RegPayloadLength
                    rfm9XDevice.RegisterWriteByte(0x40, 0b01000000);                // RegDioMapping1 0b00000000 DI0 RxReady & TxReady
                    rfm9XDevice.RegisterWriteByte(0x01, 0b10000011);                // RegOpMode

                    Debug.WriteLine($"Sending {messageBytes.Length} bytes message {messageText}");

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