Skip to content

Commit 7b96eac

Browse files
Added comment about calibration after SetDio3AsTcxoCtrl
1 parent 0e2fb82 commit 7b96eac

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

sx126x/radiocontrol_wio_sx1262.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build wio_sx1262
2+
3+
package sx126x
4+
5+
import (
6+
"machine"
7+
)
8+
9+
// NewRadioControlWio creates RadioControl configured for wio1262 module.
10+
// The board has RF_SW pin which controls RX/TX, but providing it is not required
11+
// if SetDio2AsRfSwitchCtrl is set to true (use machine.NoPin instead).
12+
// Additionally, the board requires following settings on initalization:
13+
/*
14+
radio.SetDio3AsTcxoCtrl(sx126x.SX126X_DIO3_OUTPUT_1_8, 5*time.Microsecond)
15+
radio.SetRegulatorMode(sx126x.SX126X_REGULATOR_DC_DC)
16+
radio.SetDeviceType(sx126x.DEVICE_TYPE_SX1262)
17+
radio.Calibrate(sx126x.SX126X_CALIBRATE_ALL)
18+
*/
19+
func NewRadioControlWio(nssPin, busyPin, dio1Pin, rfSw machine.Pin) *RadioControl {
20+
return &RadioControl{
21+
nssPin: nssPin,
22+
busyPin: busyPin,
23+
dio1Pin: dio1Pin,
24+
rxPin: rfSw,
25+
txLowPin: machine.NoPin,
26+
txHighPin: machine.NoPin,
27+
}
28+
}

sx126x/sx126x.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,33 @@ func (d *Device) SetDioIrqParams(irqMask, dio1Mask, dio2Mask, dio3Mask uint16) {
309309
d.ExecSetCommand(SX126X_CMD_SET_DIO_IRQ_PARAMS, p[:])
310310
}
311311

312+
// SetDio2AsRfSwitchCtrl configures if DIO2 is used to control an external RF switch.
313+
// When controlling the external RX switch, the pin DIO2 will toggle according to
314+
// the internal state machine (DIO2 = 0 in SLEEP, STDBY_RX, STDBY_XOSC, FS and RX modes,
315+
// DIO2 = 1 in TX mode). Otherwise DIO2 is free to be used as an IRQ.
316+
func (d *Device) SetDio2AsRfSwitchCtrl(enable bool) {
317+
p := [1]uint8{SX126X_DIO2_AS_IRQ}
318+
if enable {
319+
p[0] = SX126X_DIO2_AS_RF_SWITCH
320+
}
321+
d.ExecSetCommand(SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, p[:])
322+
}
323+
324+
// SetDio3AsTcxoCtrl configures the DIO3 as an external TCXO voltage reference.
325+
// After TCXO control is set, it is recommended to perform full calibration (CALIBRATE_ALL command).
326+
// voltage: output voltage on DIO3 pin
327+
// delay: time for the TCXO to stabilize
328+
func (d *Device) SetDio3AsTcxoCtrl(voltage Dio3OutputVoltage, delay time.Duration) {
329+
timeout := delay / (15625 * time.Nanosecond)
330+
var p [5]uint8
331+
p[0] = uint8(voltage)
332+
p[1] = uint8((timeout >> 24) & 0xFF)
333+
p[2] = uint8((timeout >> 16) & 0xFF)
334+
p[3] = uint8((timeout >> 8) & 0xFF)
335+
p[4] = uint8((timeout >> 0) & 0xFF)
336+
d.ExecSetCommand(SX126X_CMD_SET_DIO3_AS_TCXO_CTRL, p[:])
337+
}
338+
312339
// GetIrqStatus returns IRQ status
313340
func (d *Device) GetIrqStatus() (irqStatus uint16) {
314341
r := d.ExecGetCommand(SX126X_CMD_GET_IRQ_STATUS, 2)

0 commit comments

Comments
 (0)