Skip to content

Commit c659913

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

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
@@ -24,6 +24,7 @@
2424

2525
#include "net/lora.h"
2626
#include "periph/spi.h"
27+
#include "units.h"
2728

2829
#include "sx126x.h"
2930
#include "sx126x_regs.h"
@@ -475,11 +476,46 @@ uint32_t sx126x_get_channel(const sx126x_t *dev)
475476
return dev->channel;
476477
}
477478

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

485521
uint8_t sx126x_get_bandwidth(const sx126x_t *dev)

0 commit comments

Comments
 (0)