Skip to content

Commit 41d0fd0

Browse files
committed
drivers/sx126x: image calibration after frequency
Also changes standby configuration after image calibratin, else TCXO switches off afterwards
1 parent fd88119 commit 41d0fd0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/sx126x/sx126x.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "sx126x_netdev.h"
2424

25+
#include "macros/units.h"
2526
#include "net/lora.h"
2627
#include "periph/spi.h"
2728

@@ -465,11 +466,46 @@ uint32_t sx126x_get_channel(const sx126x_t *dev)
465466
return dev->channel;
466467
}
467468

469+
/* 9.2.1 Image Calibration for Specific Frequency Bands */
470+
static void _cal_img(sx126x_t *dev, uint32_t freq)
471+
{
472+
sx126x_chip_modes_t state = sx126x_get_state(dev);
473+
/* don't know what to do with frequencies that don't fit in the intervals from the datasheet */
474+
if (freq >= MHZ(902) && freq <= MHZ(928)) {
475+
/* 902 - 928 MHz band and anything upper */
476+
sx126x_cal_img_in_mhz(dev, 902, 928);
477+
}
478+
else if (freq >= MHZ(863) && freq <= MHZ(870)) {
479+
/* 863 - 870 MHz band */
480+
sx126x_cal_img_in_mhz(dev, 863, 870);
481+
}
482+
else if (freq >= MHZ(779) && freq <= MHZ(787)) {
483+
/* 779 - 787 MHz band */
484+
sx126x_cal_img_in_mhz(dev, 779, 787);
485+
}
486+
else if (freq >= MHZ(470) && freq <= MHZ(510)) {
487+
/* 470 - 510 MHz band */
488+
sx126x_cal_img_in_mhz(dev, 470, 510);
489+
}
490+
else if (freq >= MHZ(430) && freq <= MHZ(440)) {
491+
/* 430 - 440 MHz band and anything lower */
492+
sx126x_cal_img_in_mhz(dev, 430, 440);
493+
}
494+
else {
495+
/* Contact your Semtech representative for the other optimal calibration settings
496+
outside of the given frequency bands. */
497+
}
498+
/* Image calibration sets the chip mode back to STBY_RC */
499+
/* When using DIO3, TCXO switches off. */
500+
sx126x_set_state(dev, state);
501+
}
502+
468503
void sx126x_set_channel(sx126x_t *dev, uint32_t freq)
469504
{
470505
DEBUG("[sx126x]: sx126x_set_channel %" PRIu32 "Hz \n", freq);
471506
dev->channel = freq;
472507
sx126x_set_rf_freq(dev, dev->channel);
508+
_cal_img(dev, freq);
473509
}
474510

475511
uint8_t sx126x_get_bandwidth(const sx126x_t *dev)

0 commit comments

Comments
 (0)