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
- SX1272 shield.
- SX1276 shield.
- SX126x kit with color touch screen, or sx126x radio-only shield.
- Exceptions with their own pin assignments: NAMote-72 and Murata discovery board.
- TODO: pin assign XDOT.
TARGET_DISCO_L072CZ_LRWAN1/radio_typeABZ.cpp@5:ab124d3842a8, 2018-11-25 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Sun Nov 25 17:12:03 2018 -0800
- Revision:
- 5:ab124d3842a8
- Parent:
- 0:9c052ff8dd6a
- Child:
- 18:78c5e644d37a
add PA disable option
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:9c052ff8dd6a | 1 | #include "radio.h" |
Wayne Roberts |
0:9c052ff8dd6a | 2 | |
Wayne Roberts |
0:9c052ff8dd6a | 3 | #define SSA_BOARD 1 |
Wayne Roberts |
0:9c052ff8dd6a | 4 | |
Wayne Roberts |
5:ab124d3842a8 | 5 | #include "SPIu.h" |
Wayne Roberts |
5:ab124d3842a8 | 6 | SPIu spi(PA_7, PA_6, PB_3); // mosi, miso, sclk |
Wayne Roberts |
0:9c052ff8dd6a | 7 | // dio0, dio1, nss, spi, rst |
Wayne Roberts |
0:9c052ff8dd6a | 8 | SX127x Radio::radio(PB_4, PB_1, PA_15, spi, PC_0); // sx1276 arduino shield |
Wayne Roberts |
0:9c052ff8dd6a | 9 | SX127x_lora Radio::lora(radio); |
Wayne Roberts |
0:9c052ff8dd6a | 10 | SX127x_fsk Radio::fsk(radio); |
Wayne Roberts |
0:9c052ff8dd6a | 11 | |
Wayne Roberts |
0:9c052ff8dd6a | 12 | InterruptIn Radio::dio0(PB_4); |
Wayne Roberts |
0:9c052ff8dd6a | 13 | InterruptIn Radio::dio1(PB_1); |
Wayne Roberts |
0:9c052ff8dd6a | 14 | |
Wayne Roberts |
0:9c052ff8dd6a | 15 | #define CRF1 PA_1 |
Wayne Roberts |
0:9c052ff8dd6a | 16 | #define CRF2 PC_2 |
Wayne Roberts |
0:9c052ff8dd6a | 17 | #define CRF3 PC_1 |
Wayne Roberts |
0:9c052ff8dd6a | 18 | DigitalOut Vctl1(CRF1); |
Wayne Roberts |
0:9c052ff8dd6a | 19 | DigitalOut Vctl2(CRF2); |
Wayne Roberts |
0:9c052ff8dd6a | 20 | DigitalOut Vctl3(CRF3); |
Wayne Roberts |
0:9c052ff8dd6a | 21 | |
Wayne Roberts |
0:9c052ff8dd6a | 22 | void Radio::rfsw_callback() |
Wayne Roberts |
0:9c052ff8dd6a | 23 | { |
Wayne Roberts |
0:9c052ff8dd6a | 24 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { |
Wayne Roberts |
0:9c052ff8dd6a | 25 | Vctl1 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 26 | if (radio.RegPaConfig.bits.PaSelect) { |
Wayne Roberts |
0:9c052ff8dd6a | 27 | Vctl2 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 28 | Vctl3 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 29 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 30 | Vctl2 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 31 | Vctl3 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 32 | } |
Wayne Roberts |
0:9c052ff8dd6a | 33 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 34 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE) |
Wayne Roberts |
0:9c052ff8dd6a | 35 | Vctl1 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 36 | else |
Wayne Roberts |
0:9c052ff8dd6a | 37 | Vctl1 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 38 | |
Wayne Roberts |
0:9c052ff8dd6a | 39 | Vctl2 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 40 | Vctl3 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 41 | } |
Wayne Roberts |
0:9c052ff8dd6a | 42 | } |
Wayne Roberts |
0:9c052ff8dd6a | 43 | |
Wayne Roberts |
0:9c052ff8dd6a | 44 | void |
Wayne Roberts |
0:9c052ff8dd6a | 45 | Radio::set_tx_dbm(int8_t dbm) |
Wayne Roberts |
0:9c052ff8dd6a | 46 | { |
Wayne Roberts |
0:9c052ff8dd6a | 47 | RegPdsTrim1_t pds_trim; |
Wayne Roberts |
5:ab124d3842a8 | 48 | unsigned v = radio.read_reg(REG_PATEST_SX1276); |
Wayne Roberts |
5:ab124d3842a8 | 49 | |
Wayne Roberts |
5:ab124d3842a8 | 50 | if (dbm == PA_OFF_DBM) { |
Wayne Roberts |
5:ab124d3842a8 | 51 | /* for bench testing: prevent overloading receiving station (very low TX power) */ |
Wayne Roberts |
5:ab124d3842a8 | 52 | v &= ~0x20; // turn off pu_regpa_n: disable PA |
Wayne Roberts |
5:ab124d3842a8 | 53 | radio.write_reg(REG_PATEST_SX1276, v); |
Wayne Roberts |
5:ab124d3842a8 | 54 | return; |
Wayne Roberts |
5:ab124d3842a8 | 55 | } else if ((v & 0x20) == 0) { |
Wayne Roberts |
5:ab124d3842a8 | 56 | v |= 0x20; // turn on pu_regpa_n: enable PA |
Wayne Roberts |
5:ab124d3842a8 | 57 | radio.write_reg(REG_PATEST_SX1276, v); |
Wayne Roberts |
5:ab124d3842a8 | 58 | } |
Wayne Roberts |
5:ab124d3842a8 | 59 | |
Wayne Roberts |
0:9c052ff8dd6a | 60 | pds_trim.octet = radio.read_reg(REG_PDSTRIM1_SX1276); |
Wayne Roberts |
0:9c052ff8dd6a | 61 | |
Wayne Roberts |
0:9c052ff8dd6a | 62 | if (dbm > 13) { |
Wayne Roberts |
0:9c052ff8dd6a | 63 | radio.RegPaConfig.bits.PaSelect = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 64 | if (dbm > 17) { |
Wayne Roberts |
0:9c052ff8dd6a | 65 | pds_trim.bits.prog_txdac = 7; |
Wayne Roberts |
0:9c052ff8dd6a | 66 | dbm -= 3; |
Wayne Roberts |
0:9c052ff8dd6a | 67 | ocp(150); |
Wayne Roberts |
0:9c052ff8dd6a | 68 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 69 | pds_trim.bits.prog_txdac = 4; |
Wayne Roberts |
0:9c052ff8dd6a | 70 | ocp(120); |
Wayne Roberts |
0:9c052ff8dd6a | 71 | } |
Wayne Roberts |
0:9c052ff8dd6a | 72 | |
Wayne Roberts |
0:9c052ff8dd6a | 73 | radio.RegPaConfig.bits.OutputPower = dbm - 2; |
Wayne Roberts |
0:9c052ff8dd6a | 74 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 75 | pds_trim.bits.prog_txdac = 4; |
Wayne Roberts |
0:9c052ff8dd6a | 76 | radio.RegPaConfig.bits.PaSelect = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 77 | radio.RegPaConfig.bits.OutputPower = dbm + 1; |
Wayne Roberts |
0:9c052ff8dd6a | 78 | ocp(80); |
Wayne Roberts |
0:9c052ff8dd6a | 79 | } |
Wayne Roberts |
0:9c052ff8dd6a | 80 | |
Wayne Roberts |
0:9c052ff8dd6a | 81 | radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet); |
Wayne Roberts |
0:9c052ff8dd6a | 82 | radio.write_reg(REG_PDSTRIM1_SX1276, pds_trim.octet); |
Wayne Roberts |
0:9c052ff8dd6a | 83 | } |
Wayne Roberts |
0:9c052ff8dd6a | 84 | |
Wayne Roberts |
0:9c052ff8dd6a | 85 | #ifdef SSA_BOARD |
Wayne Roberts |
0:9c052ff8dd6a | 86 | DigitalOut pa12(PA_12); // tcxo enable |
Wayne Roberts |
0:9c052ff8dd6a | 87 | DigitalOut pa11(PA_11); // sw9v enable -> sw3v3 |
Wayne Roberts |
0:9c052ff8dd6a | 88 | #endif |
Wayne Roberts |
0:9c052ff8dd6a | 89 | void Radio::boardInit() |
Wayne Roberts |
0:9c052ff8dd6a | 90 | { |
Wayne Roberts |
0:9c052ff8dd6a | 91 | #ifdef SSA_BOARD |
Wayne Roberts |
0:9c052ff8dd6a | 92 | pa12 = 1; // tcxo |
Wayne Roberts |
0:9c052ff8dd6a | 93 | pa11 = 1; // sw9v -> sw3v3 |
Wayne Roberts |
0:9c052ff8dd6a | 94 | #endif |
Wayne Roberts |
0:9c052ff8dd6a | 95 | } |
Wayne Roberts |
0:9c052ff8dd6a | 96 |