Transmit Basic
Finally at the point where I can send a message to one of my Windows 10 IoT Core devices. Not going to use interrupts, just putting the bytes to send into the SX1276 Fifo and looping until they are sent.
//--------------------------------------------------------------------------------- // Copyright (c) August 2018, devMobile Software // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //--------------------------------------------------------------------------------- namespace devMobile.IoT.NetMF.Rfm9X.TransmitBasic { using System; using System.Text; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware.Netduino; public sealed class Rfm9XDevice { private const byte RegisterAddressReadMask = 0X7f; private const byte RegisterAddressWriteMask = 0x80; private SPI Rfm9XLoraModem = null; private OutputPort ResetGpioPin = null; public Rfm9XDevice(Cpu.Pin chipSelect, Cpu.Pin reset) { // Factory reset pin configuration ResetGpioPin = new OutputPort(Pins.GPIO_PIN_D9, true); ResetGpioPin.Write(false); Thread.Sleep(10); ResetGpioPin.Write(true); Thread.Sleep(10); //this.Rfm9XLoraModem = new SPI(new SPI.Configuration(chipSelect, false, 0, 0, false, true, 2000, SPI.SPI_module.SPI1)); this.Rfm9XLoraModem = new SPI(new SPI.Configuration(chipSelect, false, 0, 0, false, false, 2000, SPI.SPI_module.SPI1)); Thread.Sleep(100); } public Byte RegisterReadByte(byte registerAddress) { byte[] writeBuffer = new byte[] { registerAddress }; byte[] readBuffer = new byte[1]; Debug.Assert(Rfm9XLoraModem != null); //Rfm9XLoraModem.WriteRead(writeBuffer, readBuffer, 1); Rfm9XLoraModem.WriteRead(writeBuffer, readBuffer, 1); return readBuffer[0]; } public ushort RegisterReadWord(byte address) { byte[] writeBuffer = new byte[] { address &= RegisterAddressReadMask }; byte[] readBuffer = new byte[2]; Debug.Assert(Rfm9XLoraModem != null); //Rfm9XLoraModem.WriteRead(readBuffer, writeBuffer, 1 ); // Check this readBuffer[0] = RegisterReadByte(address); readBuffer[1] = RegisterReadByte(address += 1); return (ushort)(readBuffer[1] + (readBuffer[0] <<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>< 8)); } public byte[] RegisterRead(byte address, int length) { byte[] writeBuffer = new byte[] { address &= RegisterAddressReadMask }; byte[] readBuffer = new byte[length]; Debug.Assert(Rfm9XLoraModem != null); //Rfm9XLoraModem.WriteRead(readBuffer, writeBuffer, 1); // Check this for (byte index = 0; index 4]; // Mask off the upper 4 bits to get the rest of it. hexString += hexChars[singlebyte & 0x0F]; return hexString; } private static string WordToHexString(ushort singleword) { string hexString = string.Empty; byte[] bytes = BitConverter.GetBytes(singleword); hexString += ByteToHexString(bytes[1]); hexString += ByteToHexString(bytes[0]); return hexString; } } }
The debugging output of the device shows the message being transmitted
The thread '' (0x2) has exited with code 0 (0x0).
Sending 17 bytes message Hello NetMF LoRa!
Send-wait
.
.
.
.
.
Send-Done
Sending 17 bytes message Hello NetMF LoRa!
Send-wait
.
.
.
.
.
Send-Done
On my Windows 10 IoT core device I could see the messages arriving
RegIrqFlags 01010000
Receive-Message
Received 17 byte message Hello NetMF LoRa!
The thread 0x6b4 has exited with code 0 (0x0).
Sending 22 bytes message W10 IoT Core LoRa! 252
RegIrqFlags 00001000
Transmit-Done
RegIrqFlags 01010000
Receive-Message
Received 17 byte message Hello NetMF LoRa!
The program '[2932] backgroundTaskHost.exe' has exited with code -1 (0xffffffff).
All default settings for not a lot of range etc. but it works