Table of Contents

Class Sx126x

Namespace
Pamoja.Radios
Assembly
Pamoja.Radios.dll

The Semtech SX1261, SX1262, SX1268, and LLCC68 LoRa transceivers.

public static class Sx126x
Inheritance
Sx126x
Inherited Members

Remarks

Every command returns the bytes of one SPI transaction, which the caller sends once the chip's BUSY line is low, and every decoder turns the bytes the chip answered with into values. Nothing here touches a bus, so the same code plans a transmission on a host with no radio attached and checks a capture taken from one that has.

Fields

RegisterLoraSyncWord

The register the two bytes of the LoRa sync word are written to.

public const ushort RegisterLoraSyncWord = 1856

Field Value

ushort

RxContinuous

The SetRx timeout that keeps the receiver listening until told otherwise.

public const uint RxContinuous = 16777215

Field Value

uint

SyncWordPrivate

The LoRa sync word private networks use.

public const ushort SyncWordPrivate = 5156

Field Value

ushort

SyncWordPublic

The LoRa sync word public LoRaWAN networks use.

public const ushort SyncWordPublic = 13380

Field Value

ushort

Methods

CalibrateImage(uint, uint)

Builds CalibrateImage for the band a radio operates in.

public static byte[] CalibrateImage(uint lowHz, uint highHz)

Parameters

lowHz uint

The lowest frequency the radio uses, in hertz.

highHz uint

The highest frequency the radio uses, in hertz.

Returns

byte[]

The command bytes.

ClearIrqStatus(Sx126xIrq)

Builds ClearIrqStatus.

public static byte[] ClearIrqStatus(Sx126xIrq irq)

Parameters

irq Sx126xIrq

The interrupts to clear.

Returns

byte[]

The command bytes.

DeviceErrors(ReadOnlySpan<byte>)

Decodes a GetDeviceErrors answer.

public static Sx126xDeviceErrors DeviceErrors(ReadOnlySpan<byte> answer)

Parameters

answer ReadOnlySpan<byte>

The two answer bytes.

Returns

Sx126xDeviceErrors

The faults reported.

Exceptions

ArgumentException

The answer is not two bytes.

FrequencyWord(uint)

Returns the RF frequency word SetRfFrequency carries.

public static uint FrequencyWord(uint frequencyHz)

Parameters

frequencyHz uint

The carrier frequency in hertz.

Returns

uint

The frequency in steps of 32 MHz over 2^25.

GetDeviceErrors()

Builds GetDeviceErrors.

public static Sx126xQuery GetDeviceErrors()

Returns

Sx126xQuery

The query, whose answer DeviceErrors(ReadOnlySpan<byte>) decodes.

GetIrqStatus()

Builds GetIrqStatus.

public static Sx126xQuery GetIrqStatus()

Returns

Sx126xQuery

The query, whose answer Irq(ReadOnlySpan<byte>) decodes.

GetPacketStatus()

Builds GetPacketStatus.

public static Sx126xQuery GetPacketStatus()

Returns

Sx126xQuery

The query, whose answer PacketStatus(ReadOnlySpan<byte>) decodes.

GetRssiInst()

Builds GetRssiInst.

public static Sx126xQuery GetRssiInst()

Returns

Sx126xQuery

The query, whose answer RssiInstDbm(byte) decodes.

GetRxBufferStatus()

Builds GetRxBufferStatus.

public static Sx126xQuery GetRxBufferStatus()

Returns

Sx126xQuery

The query, whose answer RxBufferStatus(ReadOnlySpan<byte>) decodes.

GetStatus()

Builds GetStatus.

public static Sx126xQuery GetStatus()

Returns

Sx126xQuery

The query.

ImageCalibration(uint, uint)

Returns the CalibrateImage codes for the band a radio operates in.

public static byte[] ImageCalibration(uint lowHz, uint highHz)

Parameters

lowHz uint

The lowest frequency the radio uses, in hertz.

highHz uint

The highest frequency the radio uses, in hertz.

Returns

byte[]

The two calibration codes.

Irq(ReadOnlySpan<byte>)

Decodes a GetIrqStatus answer.

public static Sx126xIrq Irq(ReadOnlySpan<byte> answer)

Parameters

answer ReadOnlySpan<byte>

The two answer bytes.

Returns

Sx126xIrq

The interrupts raised.

Exceptions

ArgumentException

The answer is not two bytes.

Reports whether an LLCC68 supports a link's spreading factor at its bandwidth.

public static bool Llcc68Supports(LoraLink link)

Parameters

link LoraLink

The link settings.

Returns

bool

true when an LLCC68 can use the link: up to SF9 at 125 kHz, SF10 at 250 kHz, and SF11 at 500 kHz, and no bandwidth below 125 kHz.

PacketStatus(ReadOnlySpan<byte>)

Decodes a GetPacketStatus answer.

public static Sx126xPacketStatus PacketStatus(ReadOnlySpan<byte> answer)

Parameters

answer ReadOnlySpan<byte>

The three answer bytes.

Returns

Sx126xPacketStatus

The signal levels the frame was received at.

Exceptions

ArgumentException

The answer is not three bytes.

RampTimeMicros(uint)

Returns the shortest ramp time the chip offers that lasts at least a duration.

public static uint RampTimeMicros(uint atLeastMicros)

Parameters

atLeastMicros uint

The least ramp time wanted, in microseconds; past 3400, the longest ramp there is.

Returns

uint

The ramp time in microseconds.

ReadBuffer(byte, byte)

Builds ReadBuffer for a run of buffer bytes.

public static Sx126xQuery ReadBuffer(byte offset, byte length)

Parameters

offset byte

The buffer offset to read from.

length byte

How many bytes to read.

Returns

Sx126xQuery

The query.

ReadRegister(ushort, byte)

Builds ReadRegister for a run of registers.

public static Sx126xQuery ReadRegister(ushort address, byte length)

Parameters

address ushort

The first register.

length byte

How many registers to read.

Returns

Sx126xQuery

The query.

RssiInstDbm(byte)

Decodes a GetRssiInst answer.

public static double RssiInstDbm(byte value)

Parameters

value byte

The answer byte.

Returns

double

The signal level the receiver hears right now, in dBm.

RxBufferStatus(ReadOnlySpan<byte>)

Decodes a GetRxBufferStatus answer.

public static Sx126xRxBufferStatus RxBufferStatus(ReadOnlySpan<byte> answer)

Parameters

answer ReadOnlySpan<byte>

The two answer bytes.

Returns

Sx126xRxBufferStatus

The payload length and where it starts.

Exceptions

ArgumentException

The answer is not two bytes.

SetDioIrqParams(Sx126xIrq, Sx126xIrq, Sx126xIrq, Sx126xIrq)

Builds SetDioIrqParams.

public static byte[] SetDioIrqParams(Sx126xIrq irq, Sx126xIrq dio1, Sx126xIrq dio2 = Sx126xIrq.None, Sx126xIrq dio3 = Sx126xIrq.None)

Parameters

irq Sx126xIrq

The interrupts the chip raises at all.

dio1 Sx126xIrq

The interrupts that drive DIO1.

dio2 Sx126xIrq

The interrupts that drive DIO2.

dio3 Sx126xIrq

The interrupts that drive DIO3.

Returns

byte[]

The command bytes.

Builds SetModulationParams for a LoRa link.

public static byte[] SetLoraModulationParams(LoraLink link)

Parameters

link LoraLink

The link settings.

Returns

byte[]

The command bytes, with low data-rate optimization on where the datasheet asks for it.

Exceptions

PamojaException

The chip has no such bandwidth.

Builds SetPacketParams for a LoRa link.

public static byte[] SetLoraPacketParams(LoraLink link, byte payloadLength, bool invertIq)

Parameters

link LoraLink

The link settings.

payloadLength byte

The payload length in bytes.

invertIq bool

Whether to invert the IQ signals, as a LoRaWAN downlink does.

Returns

byte[]

The command bytes.

SetPaConfig(Sx126xTxPower)

Builds SetPaConfig.

public static byte[] SetPaConfig(Sx126xTxPower power)

Parameters

power Sx126xTxPower

The amplifier setting.

Returns

byte[]

The command bytes.

SetPacketTypeLora()

Builds SetPacketType for LoRa.

public static byte[] SetPacketTypeLora()

Returns

byte[]

The command bytes.

SetRfFrequency(uint)

Builds SetRfFrequency.

public static byte[] SetRfFrequency(uint frequencyHz)

Parameters

frequencyHz uint

The carrier frequency in hertz.

Returns

byte[]

The command bytes.

SetRx(ulong)

Builds SetRx.

public static byte[] SetRx(ulong timeoutMicros)

Parameters

timeoutMicros ulong

How long to listen for a frame, in microseconds; 0 listens for one frame however long it takes.

Returns

byte[]

The command bytes.

SetRxContinuous()

Builds SetRx that keeps listening, frame after frame, until told otherwise.

public static byte[] SetRxContinuous()

Returns

byte[]

The command bytes.

SetSleep(bool)

Builds SetSleep.

public static byte[] SetSleep(bool warmStart)

Parameters

warmStart bool

Whether to keep the configuration through sleep.

Returns

byte[]

The command bytes.

SetStandby()

Builds SetStandby into the RC oscillator standby.

public static byte[] SetStandby()

Returns

byte[]

The command bytes.

SetTx(ulong)

Builds SetTx.

public static byte[] SetTx(ulong timeoutMicros)

Parameters

timeoutMicros ulong

How long the chip may take to send the frame before it gives up, in microseconds; 0 waits for the frame however long it takes.

Returns

byte[]

The command bytes.

SetTxParams(Sx126xTxPower, uint)

Builds SetTxParams.

public static byte[] SetTxParams(Sx126xTxPower power, uint rampMicros)

Parameters

power Sx126xTxPower

The amplifier setting.

rampMicros uint

The least ramp time wanted, in microseconds.

Returns

byte[]

The command bytes.

Status(byte)

Decodes a status byte.

public static Sx126xStatus Status(byte value)

Parameters

value byte

The byte the chip returned.

Returns

Sx126xStatus

The operating mode and the outcome of the last command.

TimeoutSteps(ulong)

Returns a timeout in the chip's steps.

public static uint TimeoutSteps(ulong timeoutMicros)

Parameters

timeoutMicros ulong

The timeout in microseconds.

Returns

uint

The timeout in 15.625 microsecond steps, rounded up.

TxPower(Sx126xAmplifier, sbyte)

Returns the amplifier setting that delivers an output power.

public static Sx126xTxPower TxPower(Sx126xAmplifier amplifier, sbyte outputDbm)

Parameters

amplifier Sx126xAmplifier

The amplifier the chip carries.

outputDbm sbyte

The power wanted at the antenna port, in dBm.

Returns

Sx126xTxPower

The setting, clamped to what the amplifier can deliver.

TxPowerUnderCeiling(Sx126xAmplifier, LoraLinkBudget, double)

Returns the strongest amplifier setting that keeps a link under an EIRP ceiling.

public static Sx126xTxPower TxPowerUnderCeiling(Sx126xAmplifier amplifier, LoraLinkBudget budget, double eirpCeilingDbm)

Parameters

amplifier Sx126xAmplifier

The amplifier the chip carries.

budget LoraLinkBudget

The antenna gain and cable loss between the chip and the air.

eirpCeilingDbm double

The most EIRP allowed, such as a plan's limit for the channel.

Returns

Sx126xTxPower

The setting, in whole decibels rounded down so the ceiling holds.

WriteBuffer(byte, ReadOnlySpan<byte>)

Builds WriteBuffer for a payload.

public static byte[] WriteBuffer(byte offset, ReadOnlySpan<byte> payload)

Parameters

offset byte

The buffer offset the payload starts at.

payload ReadOnlySpan<byte>

The payload.

Returns

byte[]

The whole transaction: the header followed by the payload.

WriteRegister(ushort, ReadOnlySpan<byte>)

Builds WriteRegister for a run of registers.

public static byte[] WriteRegister(ushort address, ReadOnlySpan<byte> values)

Parameters

address ushort

The first register.

values ReadOnlySpan<byte>

The values, one per register.

Returns

byte[]

The whole transaction: the header followed by the values.