Main Site Documentation

Working Nordic nRF24L01+ radio driver

The driver here:


("C# library for the nRF24L01+ radio for Windows IoT Core ") appears to work under TinyCLR OS with minor modification to file RF24.cs

//***FROM using System.Threading.Tasks;
//***FROM using Windows.Devices.Gpio;
//***FROM using Windows.Devices.Spi;
using GHIElectronics.TinyCLR.Devices.Gpio; //***TO
using GHIElectronics.TinyCLR.Devices.Spi; //***TO

//***FROM throw new ArgumentOutOfRangeException(“Channel”, value, "Channel cannot be greater than " + MAX_CHANNEL);
throw new ArgumentOutOfRangeException("Channel " + value.ToString(), "Channel cannot be greater than " + MAX_CHANNEL); //***TO

//***FROM throw new ArgumentOutOfRangeException(“DataRate”, value, “An invalid DataRate was specified”);
throw new ArgumentOutOfRangeException("DataRate " + value.ToString(), “An invalid DataRate was specified”); //***TO

//***FROM public void Initialize(byte chipEnablePin, byte chipSelectLine, byte interruptPin)
public void Initialize(string spi, int chipEnablePin, int chipSelectLine, int interruptPin) //***TO

//***FROM var settings = new SpiConnectionSettings(chipSelectLine);
//***FROM settings.ClockFrequency = 2000000;
//***FROM settings.Mode = SpiMode.Mode0;
var settings = new SpiConnectionSettings() //***TO
{ //***TO
ChipSelectType = SpiChipSelectType.Gpio, //***TO
ChipSelectLine = chipSelectLine, //***TO
ClockFrequency = 2000000, //***TO
Mode = SpiMode.Mode0, //***TO
}; //***TO

//***FROM SpiController controller = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
SpiController controller = SpiController.FromName(spi); //***TO

//***FROM Task.Delay(100).GetAwaiter().GetResult();
Thread.Sleep(100); //***TO

//***FROM if (WaitHandle.WaitAny(new[] { _transmitSuccessFlag, _transmitFailedFlag }, 200) == 0)
if (WaitHandle.WaitAny(new[] { _transmitSuccessFlag, _transmitFailedFlag }, 200, true) == 0) //***TO

//***FROM Debug.Write(“Retransmitting packet…”);
Debug.WriteLine(“Retransmitting packet…”); //***TO

//***FROM Debug.WriteLine("Interrupt Triggered: " + args.Edge.ToString());
Debug.WriteLine("Interrupt Triggered: " + args.Edge); //***TO

4 Likes