Hardware Abstraction Layer, permitting any LoRa application to use any LoRa radio chip

Dependents:   alarm_slave alarm_master lora_p2p lorawan1v1 ... more

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
if you're using LR1110, then import LR1110 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
If you're using Type1SJ select target DISCO_L072CZ_LRWAN1 and import sx126x driver into your program.

Pin assigned to arduino LoRa radio shield form-factor

Committer:
Wayne Roberts
Date:
Fri Feb 05 16:35:05 2021 -0800
Revision:
21:96db08266089
Parent:
18:78c5e644d37a
lr1110: handle tcxo when hf-xosc fails to start

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:9c052ff8dd6a 1 #include "radio.h"
Wayne Roberts 18:78c5e644d37a 2 #ifdef SX127x_H
Wayne Roberts 0:9c052ff8dd6a 3
Wayne Roberts 0:9c052ff8dd6a 4 #define SSA_BOARD 1
Wayne Roberts 0:9c052ff8dd6a 5
Wayne Roberts 5:ab124d3842a8 6 #include "SPIu.h"
Wayne Roberts 5:ab124d3842a8 7 SPIu spi(PA_7, PA_6, PB_3); // mosi, miso, sclk
Wayne Roberts 0:9c052ff8dd6a 8 // dio0, dio1, nss, spi, rst
Wayne Roberts 0:9c052ff8dd6a 9 SX127x Radio::radio(PB_4, PB_1, PA_15, spi, PC_0); // sx1276 arduino shield
Wayne Roberts 0:9c052ff8dd6a 10 SX127x_lora Radio::lora(radio);
Wayne Roberts 0:9c052ff8dd6a 11 SX127x_fsk Radio::fsk(radio);
Wayne Roberts 0:9c052ff8dd6a 12
Wayne Roberts 0:9c052ff8dd6a 13 InterruptIn Radio::dio0(PB_4);
Wayne Roberts 0:9c052ff8dd6a 14 InterruptIn Radio::dio1(PB_1);
Wayne Roberts 0:9c052ff8dd6a 15
Wayne Roberts 0:9c052ff8dd6a 16 #define CRF1 PA_1
Wayne Roberts 0:9c052ff8dd6a 17 #define CRF2 PC_2
Wayne Roberts 0:9c052ff8dd6a 18 #define CRF3 PC_1
Wayne Roberts 0:9c052ff8dd6a 19 DigitalOut Vctl1(CRF1);
Wayne Roberts 0:9c052ff8dd6a 20 DigitalOut Vctl2(CRF2);
Wayne Roberts 0:9c052ff8dd6a 21 DigitalOut Vctl3(CRF3);
Wayne Roberts 0:9c052ff8dd6a 22
Wayne Roberts 0:9c052ff8dd6a 23 void Radio::rfsw_callback()
Wayne Roberts 0:9c052ff8dd6a 24 {
Wayne Roberts 0:9c052ff8dd6a 25 if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
Wayne Roberts 0:9c052ff8dd6a 26 Vctl1 = 0;
Wayne Roberts 0:9c052ff8dd6a 27 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 0:9c052ff8dd6a 28 Vctl2 = 0;
Wayne Roberts 0:9c052ff8dd6a 29 Vctl3 = 1;
Wayne Roberts 0:9c052ff8dd6a 30 } else {
Wayne Roberts 0:9c052ff8dd6a 31 Vctl2 = 1;
Wayne Roberts 0:9c052ff8dd6a 32 Vctl3 = 0;
Wayne Roberts 0:9c052ff8dd6a 33 }
Wayne Roberts 0:9c052ff8dd6a 34 } else {
Wayne Roberts 0:9c052ff8dd6a 35 if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
Wayne Roberts 0:9c052ff8dd6a 36 Vctl1 = 1;
Wayne Roberts 0:9c052ff8dd6a 37 else
Wayne Roberts 0:9c052ff8dd6a 38 Vctl1 = 0;
Wayne Roberts 0:9c052ff8dd6a 39
Wayne Roberts 0:9c052ff8dd6a 40 Vctl2 = 0;
Wayne Roberts 0:9c052ff8dd6a 41 Vctl3 = 0;
Wayne Roberts 0:9c052ff8dd6a 42 }
Wayne Roberts 0:9c052ff8dd6a 43 }
Wayne Roberts 0:9c052ff8dd6a 44
Wayne Roberts 0:9c052ff8dd6a 45 void
Wayne Roberts 0:9c052ff8dd6a 46 Radio::set_tx_dbm(int8_t dbm)
Wayne Roberts 0:9c052ff8dd6a 47 {
Wayne Roberts 0:9c052ff8dd6a 48 RegPdsTrim1_t pds_trim;
Wayne Roberts 5:ab124d3842a8 49 unsigned v = radio.read_reg(REG_PATEST_SX1276);
Wayne Roberts 5:ab124d3842a8 50
Wayne Roberts 5:ab124d3842a8 51 if (dbm == PA_OFF_DBM) {
Wayne Roberts 5:ab124d3842a8 52 /* for bench testing: prevent overloading receiving station (very low TX power) */
Wayne Roberts 5:ab124d3842a8 53 v &= ~0x20; // turn off pu_regpa_n: disable PA
Wayne Roberts 5:ab124d3842a8 54 radio.write_reg(REG_PATEST_SX1276, v);
Wayne Roberts 5:ab124d3842a8 55 return;
Wayne Roberts 5:ab124d3842a8 56 } else if ((v & 0x20) == 0) {
Wayne Roberts 5:ab124d3842a8 57 v |= 0x20; // turn on pu_regpa_n: enable PA
Wayne Roberts 5:ab124d3842a8 58 radio.write_reg(REG_PATEST_SX1276, v);
Wayne Roberts 5:ab124d3842a8 59 }
Wayne Roberts 5:ab124d3842a8 60
Wayne Roberts 0:9c052ff8dd6a 61 pds_trim.octet = radio.read_reg(REG_PDSTRIM1_SX1276);
Wayne Roberts 0:9c052ff8dd6a 62
Wayne Roberts 0:9c052ff8dd6a 63 if (dbm > 13) {
Wayne Roberts 0:9c052ff8dd6a 64 radio.RegPaConfig.bits.PaSelect = 1;
Wayne Roberts 0:9c052ff8dd6a 65 if (dbm > 17) {
Wayne Roberts 0:9c052ff8dd6a 66 pds_trim.bits.prog_txdac = 7;
Wayne Roberts 0:9c052ff8dd6a 67 dbm -= 3;
Wayne Roberts 0:9c052ff8dd6a 68 ocp(150);
Wayne Roberts 0:9c052ff8dd6a 69 } else {
Wayne Roberts 0:9c052ff8dd6a 70 pds_trim.bits.prog_txdac = 4;
Wayne Roberts 0:9c052ff8dd6a 71 ocp(120);
Wayne Roberts 0:9c052ff8dd6a 72 }
Wayne Roberts 0:9c052ff8dd6a 73
Wayne Roberts 0:9c052ff8dd6a 74 radio.RegPaConfig.bits.OutputPower = dbm - 2;
Wayne Roberts 0:9c052ff8dd6a 75 } else {
Wayne Roberts 0:9c052ff8dd6a 76 pds_trim.bits.prog_txdac = 4;
Wayne Roberts 0:9c052ff8dd6a 77 radio.RegPaConfig.bits.PaSelect = 0;
Wayne Roberts 0:9c052ff8dd6a 78 radio.RegPaConfig.bits.OutputPower = dbm + 1;
Wayne Roberts 0:9c052ff8dd6a 79 ocp(80);
Wayne Roberts 0:9c052ff8dd6a 80 }
Wayne Roberts 0:9c052ff8dd6a 81
Wayne Roberts 0:9c052ff8dd6a 82 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 0:9c052ff8dd6a 83 radio.write_reg(REG_PDSTRIM1_SX1276, pds_trim.octet);
Wayne Roberts 0:9c052ff8dd6a 84 }
Wayne Roberts 0:9c052ff8dd6a 85
Wayne Roberts 0:9c052ff8dd6a 86 #ifdef SSA_BOARD
Wayne Roberts 0:9c052ff8dd6a 87 DigitalOut pa12(PA_12); // tcxo enable
Wayne Roberts 0:9c052ff8dd6a 88 DigitalOut pa11(PA_11); // sw9v enable -> sw3v3
Wayne Roberts 0:9c052ff8dd6a 89 #endif
Wayne Roberts 0:9c052ff8dd6a 90 void Radio::boardInit()
Wayne Roberts 0:9c052ff8dd6a 91 {
Wayne Roberts 0:9c052ff8dd6a 92 #ifdef SSA_BOARD
Wayne Roberts 0:9c052ff8dd6a 93 pa12 = 1; // tcxo
Wayne Roberts 0:9c052ff8dd6a 94 pa11 = 1; // sw9v -> sw3v3
Wayne Roberts 0:9c052ff8dd6a 95 #endif
Wayne Roberts 0:9c052ff8dd6a 96 }
Wayne Roberts 0:9c052ff8dd6a 97
Wayne Roberts 18:78c5e644d37a 98 #endif /* ..SX127x_H */