RFM69 shield library Part2

Register Dump

Next step was to dump all registers (0x00 RegFifo thru 0x4F RegTemp2) of the RFM69HCW device.

/*
    Copyright ® 2019 May devMobile Software, All Rights Reserved

	 MIT License


	 Permission is hereby granted, free of charge, to any person obtaining a copy
	 of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
	 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	 copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
	 copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	 SOFTWARE

	 RegFiFo 0x00 thru RegPacketConfig2 0x3D

*/
namespace devMobile.IoT.Rfm69Hcw.RegisterScan
{
	using System;
	using System.Diagnostics;
	using System.Threading.Tasks;
	using Windows.ApplicationModel.Background;
	using Windows.Devices.Spi;

	public sealed class Rfm69HcwDevice
	{
		private SpiDevice rfm69Hcw;

		public Rfm69HcwDevice(int chipSelectPin)
		{
			SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
			var settings = new SpiConnectionSettings(chipSelectPin)
			{
				ClockFrequency = 500000,
				Mode = SpiMode.Mode0,
			};

			rfm69Hcw = spiController.GetDevice(settings);
		}

		public Byte RegisterReadByte(byte registerAddress)
		{
			byte[] writeBuffer = new byte[] { registerAddress };
			byte[] readBuffer = new byte[1];
			Debug.Assert(rfm69Hcw != null);

			rfm69Hcw.TransferSequential(writeBuffer, readBuffer);

			return readBuffer[0];
		}
	}

	public sealed class StartupTask : IBackgroundTask
	{
		private const int ChipSelectLine = 0;
		private Rfm69HcwDevice rfm69HcwDevice = new Rfm69HcwDevice(ChipSelectLine);

		public void Run(IBackgroundTaskInstance taskInstance)
		{

			while (true)
			{
				for (byte registerIndex = 0; registerIndex <= 0x4F; registerIndex++)
				{
					byte registerValue = rfm69HcwDevice.RegisterReadByte(registerIndex);

					Debug.WriteLine("Register 0x{0:x2} - Value 0X{1:x2} - Bits {2}", registerIndex, registerValue, Convert.ToString(registerValue, 2).PadLeft(8, '0'));
				}

				Task.Delay(10000).Wait();
			}
		}
	}
}

I checked a selection of values from the Debug output and they matched the defaults in the datasheet e.g. 0x07-RegFrfMsb 0xE4, 0x08-RegFrfMid 0xC0, 0x09-RegFrfLsb 0x00, 0x2C-RegPreamble 0x0, 0x2D-RegPreamble 0x03 and 0x4E-RegTemp1 0x01.

Register 0x00 - Value 0X00 - Bits 00000000
Register 0x01 - Value 0X04 - Bits 00000100
Register 0x02 - Value 0X00 - Bits 00000000
Register 0x03 - Value 0X1a - Bits 00011010
Register 0x04 - Value 0X0b - Bits 00001011
Register 0x05 - Value 0X00 - Bits 00000000
Register 0x06 - Value 0X52 - Bits 01010010
Register 0x07 - Value 0Xe4 - Bits 11100100
Register 0x08 - Value 0Xc0 - Bits 11000000
Register 0x09 - Value 0X00 - Bits 00000000
Register 0x0a - Value 0X41 - Bits 01000001
Register 0x0b - Value 0X40 - Bits 01000000
Register 0x0c - Value 0X02 - Bits 00000010
Register 0x0d - Value 0X92 - Bits 10010010
Register 0x0e - Value 0Xf5 - Bits 11110101
Register 0x0f - Value 0X20 - Bits 00100000
Register 0x10 - Value 0X24 - Bits 00100100
Register 0x11 - Value 0X9f - Bits 10011111
Register 0x12 - Value 0X09 - Bits 00001001
Register 0x13 - Value 0X1a - Bits 00011010
Register 0x14 - Value 0X40 - Bits 01000000
Register 0x15 - Value 0Xb0 - Bits 10110000
Register 0x16 - Value 0X7b - Bits 01111011
Register 0x17 - Value 0X9b - Bits 10011011
Register 0x18 - Value 0X08 - Bits 00001000
Register 0x19 - Value 0X86 - Bits 10000110
Register 0x1a - Value 0X8a - Bits 10001010
Register 0x1b - Value 0X40 - Bits 01000000
Register 0x1c - Value 0X80 - Bits 10000000
Register 0x1d - Value 0X06 - Bits 00000110
Register 0x1e - Value 0X10 - Bits 00010000
Register 0x1f - Value 0X00 - Bits 00000000
Register 0x20 - Value 0X00 - Bits 00000000
Register 0x21 - Value 0X00 - Bits 00000000
Register 0x22 - Value 0X00 - Bits 00000000
Register 0x23 - Value 0X02 - Bits 00000010
Register 0x24 - Value 0Xff - Bits 11111111
Register 0x25 - Value 0X00 - Bits 00000000
Register 0x26 - Value 0X05 - Bits 00000101
Register 0x27 - Value 0X80 - Bits 10000000
Register 0x28 - Value 0X00 - Bits 00000000
Register 0x29 - Value 0Xff - Bits 11111111
Register 0x2a - Value 0X00 - Bits 00000000
Register 0x2b - Value 0X00 - Bits 00000000
Register 0x2c - Value 0X00 - Bits 00000000
Register 0x2d - Value 0X03 - Bits 00000011
Register 0x2e - Value 0X98 - Bits 10011000
Register 0x2f - Value 0X00 - Bits 00000000
Register 0x30 - Value 0X00 - Bits 00000000
Register 0x31 - Value 0X00 - Bits 00000000
Register 0x32 - Value 0X00 - Bits 00000000
Register 0x33 - Value 0X00 - Bits 00000000
Register 0x34 - Value 0X00 - Bits 00000000
Register 0x35 - Value 0X00 - Bits 00000000
Register 0x36 - Value 0X00 - Bits 00000000
Register 0x37 - Value 0X10 - Bits 00010000
Register 0x38 - Value 0X40 - Bits 01000000
Register 0x39 - Value 0X00 - Bits 00000000
Register 0x3a - Value 0X00 - Bits 00000000
Register 0x3b - Value 0X00 - Bits 00000000
Register 0x3c - Value 0X0f - Bits 00001111
Register 0x3d - Value 0X02 - Bits 00000010
Register 0x3e - Value 0X00 - Bits 00000000
Register 0x3f - Value 0X00 - Bits 00000000
Register 0x40 - Value 0X00 - Bits 00000000
Register 0x41 - Value 0X00 - Bits 00000000
Register 0x42 - Value 0X00 - Bits 00000000
Register 0x43 - Value 0X00 - Bits 00000000
Register 0x44 - Value 0X00 - Bits 00000000
Register 0x45 - Value 0X00 - Bits 00000000
Register 0x46 - Value 0X00 - Bits 00000000
Register 0x47 - Value 0X00 - Bits 00000000
Register 0x48 - Value 0X00 - Bits 00000000
Register 0x49 - Value 0X00 - Bits 00000000
Register 0x4a - Value 0X00 - Bits 00000000
Register 0x4b - Value 0X00 - Bits 00000000
Register 0x4c - Value 0X00 - Bits 00000000
Register 0x4d - Value 0X00 - Bits 00000000
Register 0x4e - Value 0X01 - Bits 00000001
Register 0x4f - Value 0X00 - Bits 00000000

RFM69 shield library Part1

Register Read

After building an RFM95 Windows 10 IoT Core C# library I wanted to see if I could source a couple of RFM69HCW hats and write another library. For some applications the RFM69HCW with the variety and number of low-power client devices available plus, its built in payload encryption and addressing make it a better option. For the RFM9X library I purchased several RM9X Raspberry PI Hats but I can only find a couple (May 2019) of suitable RFM69HCW ones.

  • Adafruit RFM69HCW Radio Bonnet 433/868/915MHz USD19.95
  • Seegel Systeme RaspyRFMII EUR17.90

I wanted a lightweight RFM69HCW library which didn’t try to hide how the chip functioned, and in the future could be configured to work with other vendors’ shields.

AdaFruit LoRa 9X/RFM69HCW Radio Bonnet
Seegel Systeme RaspyRFM-II

The first step was to build a basic universal windows platform (UWP) background task to confirm that I could reliably communicate with the AdaFruit shield over the SPI bus by reading a single register value (RegVersion the silicon version specified in the vendor datasheet).

/*
    Copyright ® 2019 May devMobile Software, All Rights Reserved
 
    MIT License

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE

	 CS : CE1
	 RST : GPIO25
	 IRQ : GPIO22 (DIO0)
	 Unused : GPIO23 (DIO1)
	 Unused : GPIO24 (DIO2)
 */
namespace devMobile.IoT.Rfm69hcw.AdafruitSPI
{
	using System;
	using System.Diagnostics;
	using System.Threading;
	using Windows.ApplicationModel.Background;
	using Windows.Devices.Spi;

	public sealed class StartupTask : IBackgroundTask
	{
		private const byte RegVersion = 0x10;

		public void Run(IBackgroundTaskInstance taskInstance)
		{
			SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
			var settings = new SpiConnectionSettings(1)
			{
				ClockFrequency = 500000,
				Mode = SpiMode.Mode0,
			};

			SpiDevice Device = spiController.GetDevice(settings);

			while (true)
			{
				byte[] writeBuffer = new byte[] { RegVersion }; // RegVersion
				byte[] readBuffer = new byte[1];

				Device.TransferSequential(writeBuffer, readBuffer);

				byte registerValue = readBuffer[0];
				Debug.WriteLine("Register 0x{0:x2} - Value 0X{1:x2} - Bits {2}", RegVersion, registerValue, Convert.ToString(registerValue, 2).PadLeft(8, '0'));

				Thread.Sleep(10000);
			}
		}
	}
}

The AdaFruit hat uses chip select 1

/*
    Copyright ® 2019 May devMobile Software, All Rights Reserved
 
    MIT License

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE

    The RaspyRFM is plugged into the Raspberry PI of pin 17-26.

    From the docs for the dual RFM69 mini 
    17 -> 3,3 V
    18 (GPIO 24) -> DIO1 bei Einzelmodul, DIO0 Slave bei Doppelmodul
    19 (MOSI) -> MOSI
    20 -> GND
    21 (MISO) ->MISO
    22 (GPIO 25) -> DIO0
    23 (SCK) -> SCK
    24 (CE0) -> NSS Master
    25 -> GND
    26 (CE1) -> DIO2 bei Einzelmodul, NSS Slave bei Doppelmodul
 */
namespace devMobile.IoT.Rfm69hcw.SeegelSpi
{
	using System;
	using System.Diagnostics;
	using System.Threading;
	using Windows.ApplicationModel.Background;
	using Windows.Devices.Spi;

	public sealed class StartupTask : IBackgroundTask
	{
		private const byte RegVersion = 0x10;

		public void Run(IBackgroundTaskInstance taskInstance)
		{
			SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
			var settings = new SpiConnectionSettings(0)
			{
				ClockFrequency = 500000,
				Mode = SpiMode.Mode0,
			};

			SpiDevice Device = spiController.GetDevice(settings);

			while (true)
			{
				byte[] writeBuffer = new byte[] { RegVersion }; // RegVersion
				byte[] readBuffer = new byte[1];

				Device.TransferSequential(writeBuffer, readBuffer);

				byte registerValue = readBuffer[0];
				Debug.WriteLine("Register 0x{0:x2} - Value 0X{1:x2} - Bits {2}", RegVersion, registerValue, Convert.ToString(registerValue, 2).PadLeft(8, '0'));

				Thread.Sleep(10000);
			}
		}
	}
}


The Seegel hat uses chip select 0

Based on the datasheet the RegVersion (0x10) register the value (ox24) returned by both hats was correct.

'backgroundTaskHost.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Programs\WindowsApps\Microsoft.NET.CoreFramework.Debug.2.2_2.2.27505.2_arm__8wekyb3d8bbwe\System.Threading.Thread.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Register 0x10 - Value 0X24 - Bits 00100100
Register 0x10 - Value 0X24 - Bits 00100100
Register 0x10 - Value 0X24 - Bits 00100100

Next step is to dump all the registers of the HopeRF module