transfer files from mbed-os block device (i.e. SD card) over LoRa radio.
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 NAmote72 or Murata discovery, then you must import only sx127x driver.
This program uses mbed serial terminal at 115200 8N1.
Files (on SD Card) are transferred between two LoRa devices.
Use ? question mark to see available commands on serial terminal.
Send file to other side using send /fs/somefile
, then use cmp /fs/somefile
to compare the file on the other side of radio link with local file with same name.
Use cmp
to test radio link.rm
command to delete files must not include /fs/
directory prefix, filename only.
send
and cmp
require /fs/
directory.
sx1280 thruput
bytes/sec | sf12 | sf11 | sf10 | sf9 | sf8 | sf7 | sf6 | sf5 |
1600KHz | 276 | 482 | 1081 | 1887 | 3277 | 5365 | 6400 | 12000 |
800KHz | 529 | 970 | 1720 | 2800 | 4766 | 6500 | ||
400KHz | 1465 | 2265 | 4033 |
sx126x thruput
bytes/sec | sf12 | sf11 | sf10 | sf9 | sf8 | sf7 | sf6 | sf5 |
500KHz | 207 | 381 | 706 | 1257 | 2154 | 3570 | 5608 | |
250KHz | 103 | 193 | 344 | 641 | 1114 | 1887 | 3064 | |
125KHz | 97 | 173 | 324 | 547 | 972 | 1607 |
sx127x thruput
sx126x recommended at 500KHz bandwidth.
bytes/sec | sf12 | sf11 | sf10 | sf9 | sf8 | sf7 |
500KHz | 111 | 207 | 385 | 697 | 1220 | 2050 |
250KHz | 48.7 | 103 | 192 | 345 | 632 | 1115 |
125KHz | 24.2 | 44 | 97 | 151 | 313 | 552 |
62.5KHz | 12.2 | 22.1 | 39.4 | 86 | 157 | 276 |
SD Card
SD card driver must be enabled in mbed_app.json
with the line "target.components_add": ["SD"]
Pins for SD card connection can be overridden as shown in mbed_app.json
.
The default pin configuration for SD card is found in mbed_lib.json
in mbed-os/components/storage/blockdevice/COMPONENT_SD/
.
If no pin configuration exists in this mbed_lib.json
, or needs to be changed, the included mbed_app.json
is example pin declaration for SD card.
FAT filesystem is only used in this project for demonstration purpose; for easily copying files to SD card.
However, for production projects, LittleFileSystem needs to be used instead for reliability and wear leveling.
Platforms such as K64F have SD card slot already.
See all boards with arduino shield connector and SD card here. (arduino connector needed for LoRa radio board)
...but if you want to use nucleo board:
lorachip_sx126x.cpp@1:319ef808aaa4, 2019-06-05 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Wed Jun 05 09:52:27 2019 -0700
- Revision:
- 1:319ef808aaa4
- Parent:
- 0:c3ecf7b252a3
mbed crashes closing -1 file descriptor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:c3ecf7b252a3 | 1 | #include "lorachip.h" |
Wayne Roberts |
0:c3ecf7b252a3 | 2 | #ifdef SX126x_H |
Wayne Roberts |
0:c3ecf7b252a3 | 3 | |
Wayne Roberts |
0:c3ecf7b252a3 | 4 | PacketParams_t ppLORA; |
Wayne Roberts |
0:c3ecf7b252a3 | 5 | ModulationParams_t mpLORA; |
Wayne Roberts |
0:c3ecf7b252a3 | 6 | uint8_t tx_param_buf[2]; |
Wayne Roberts |
0:c3ecf7b252a3 | 7 | uint8_t pa_config_buf[4]; |
Wayne Roberts |
0:c3ecf7b252a3 | 8 | |
Wayne Roberts |
0:c3ecf7b252a3 | 9 | void tx_dbm_print() |
Wayne Roberts |
0:c3ecf7b252a3 | 10 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 11 | PwrCtrl_t PwrCtrl; |
Wayne Roberts |
0:c3ecf7b252a3 | 12 | PaCtrl1b_t PaCtrl1b; |
Wayne Roberts |
0:c3ecf7b252a3 | 13 | unsigned v = Radio::radio.readReg(REG_ADDR_ANACTRL16, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 14 | |
Wayne Roberts |
0:c3ecf7b252a3 | 15 | if (v & 0x10) { |
Wayne Roberts |
0:c3ecf7b252a3 | 16 | pc.printf("%d", PA_OFF_DBM); |
Wayne Roberts |
0:c3ecf7b252a3 | 17 | return; |
Wayne Roberts |
0:c3ecf7b252a3 | 18 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 19 | |
Wayne Roberts |
0:c3ecf7b252a3 | 20 | PwrCtrl.octet = Radio::radio.readReg(REG_ADDR_PWR_CTRL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 21 | |
Wayne Roberts |
0:c3ecf7b252a3 | 22 | PaCtrl1b.octet = Radio::radio.readReg(REG_ADDR_PA_CTRL1B, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 23 | pa_config_buf[2] = PaCtrl1b.bits.tx_mode_bat; // deviceSel |
Wayne Roberts |
0:c3ecf7b252a3 | 24 | |
Wayne Roberts |
0:c3ecf7b252a3 | 25 | pc.printf("%ddBm ", PwrCtrl.bits.tx_pwr - (PaCtrl1b.bits.tx_mode_bat ? 17 : 9)); |
Wayne Roberts |
0:c3ecf7b252a3 | 26 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 27 | |
Wayne Roberts |
0:c3ecf7b252a3 | 28 | void cmd_frf(uint8_t argsAt) |
Wayne Roberts |
0:c3ecf7b252a3 | 29 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 30 | float MHz; |
Wayne Roberts |
0:c3ecf7b252a3 | 31 | |
Wayne Roberts |
0:c3ecf7b252a3 | 32 | if (sscanf(pcbuf + argsAt, "%f", &MHz) == 1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 33 | Radio::radio.setMHz(MHz); |
Wayne Roberts |
0:c3ecf7b252a3 | 34 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 35 | MHz = Radio::radio.getMHz(); |
Wayne Roberts |
0:c3ecf7b252a3 | 36 | pc.printf("%.3fMHz\r\n", MHz); |
Wayne Roberts |
0:c3ecf7b252a3 | 37 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 38 | |
Wayne Roberts |
0:c3ecf7b252a3 | 39 | const uint8_t loraBWs[] = { |
Wayne Roberts |
0:c3ecf7b252a3 | 40 | LORA_BW_7, LORA_BW_10, LORA_BW_15, |
Wayne Roberts |
0:c3ecf7b252a3 | 41 | LORA_BW_20, LORA_BW_31, LORA_BW_41, |
Wayne Roberts |
0:c3ecf7b252a3 | 42 | LORA_BW_62, LORA_BW_125, LORA_BW_250, |
Wayne Roberts |
0:c3ecf7b252a3 | 43 | LORA_BW_500 |
Wayne Roberts |
0:c3ecf7b252a3 | 44 | }; |
Wayne Roberts |
0:c3ecf7b252a3 | 45 | |
Wayne Roberts |
0:c3ecf7b252a3 | 46 | static const float lora_bws[] = { |
Wayne Roberts |
0:c3ecf7b252a3 | 47 | 7.81, 10.42, 15.63, |
Wayne Roberts |
0:c3ecf7b252a3 | 48 | 20.83, 31.25, 41.67, |
Wayne Roberts |
0:c3ecf7b252a3 | 49 | 62.5, 125, 250, |
Wayne Roberts |
0:c3ecf7b252a3 | 50 | 500, |
Wayne Roberts |
0:c3ecf7b252a3 | 51 | 0 |
Wayne Roberts |
0:c3ecf7b252a3 | 52 | }; |
Wayne Roberts |
0:c3ecf7b252a3 | 53 | |
Wayne Roberts |
0:c3ecf7b252a3 | 54 | void print_lora_status() |
Wayne Roberts |
0:c3ecf7b252a3 | 55 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 56 | status_t status; |
Wayne Roberts |
0:c3ecf7b252a3 | 57 | float MHz; |
Wayne Roberts |
0:c3ecf7b252a3 | 58 | unsigned n; |
Wayne Roberts |
0:c3ecf7b252a3 | 59 | loraConfig0_t conf0; |
Wayne Roberts |
0:c3ecf7b252a3 | 60 | |
Wayne Roberts |
0:c3ecf7b252a3 | 61 | tx_dbm_print(); |
Wayne Roberts |
0:c3ecf7b252a3 | 62 | Radio::radio.xfer(OPCODE_GET_STATUS, 0, 1, &status.octet); |
Wayne Roberts |
0:c3ecf7b252a3 | 63 | |
Wayne Roberts |
0:c3ecf7b252a3 | 64 | pc.printf(" "); |
Wayne Roberts |
0:c3ecf7b252a3 | 65 | /* translate opmode_status_strs to opmode_select_strs */ |
Wayne Roberts |
0:c3ecf7b252a3 | 66 | switch (status.bits.chipMode) { |
Wayne Roberts |
0:c3ecf7b252a3 | 67 | case 2: pc.printf("STBY_RC"); break; // STBY_RC |
Wayne Roberts |
0:c3ecf7b252a3 | 68 | case 3: pc.printf("STBY_XOSC"); break; // STBY_XOSC |
Wayne Roberts |
0:c3ecf7b252a3 | 69 | case 4: pc.printf("FS"); break; // FS |
Wayne Roberts |
0:c3ecf7b252a3 | 70 | case 5: pc.printf("RX"); break; // RX |
Wayne Roberts |
0:c3ecf7b252a3 | 71 | case 6: pc.printf("TX"); break; // TX |
Wayne Roberts |
0:c3ecf7b252a3 | 72 | default: pc.printf("<%d>", status.bits.chipMode); break; |
Wayne Roberts |
0:c3ecf7b252a3 | 73 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 74 | pc.printf("\t"); |
Wayne Roberts |
0:c3ecf7b252a3 | 75 | |
Wayne Roberts |
0:c3ecf7b252a3 | 76 | conf0.octet = Radio::radio.readReg(REG_ADDR_LORA_CONFIG0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 77 | mpLORA.lora.bandwidth = conf0.bits.modem_bw; |
Wayne Roberts |
0:c3ecf7b252a3 | 78 | for (n = 0; n < sizeof(loraBWs); n++) { |
Wayne Roberts |
0:c3ecf7b252a3 | 79 | if (conf0.bits.modem_bw == loraBWs[n]) { |
Wayne Roberts |
0:c3ecf7b252a3 | 80 | pc.printf("%.1fKHz ", lora_bws[n]); |
Wayne Roberts |
0:c3ecf7b252a3 | 81 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 82 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 83 | mpLORA.lora.spreadingFactor = conf0.bits.modem_sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 84 | pc.printf("sf%u ", conf0.bits.modem_sf); |
Wayne Roberts |
0:c3ecf7b252a3 | 85 | |
Wayne Roberts |
0:c3ecf7b252a3 | 86 | MHz = Radio::radio.getMHz(); |
Wayne Roberts |
0:c3ecf7b252a3 | 87 | pc.printf(" %.3fMHz\r\n", MHz); |
Wayne Roberts |
0:c3ecf7b252a3 | 88 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 89 | |
Wayne Roberts |
0:c3ecf7b252a3 | 90 | void cmd_sf(uint8_t argsAt) |
Wayne Roberts |
0:c3ecf7b252a3 | 91 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 92 | loraConfig0_t conf0; |
Wayne Roberts |
0:c3ecf7b252a3 | 93 | unsigned sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 94 | |
Wayne Roberts |
0:c3ecf7b252a3 | 95 | if (sscanf(pcbuf + argsAt, "%u", &sf) == 1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 96 | mpLORA.lora.spreadingFactor = sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 97 | Radio::radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, 0, mpLORA.buf); |
Wayne Roberts |
0:c3ecf7b252a3 | 98 | |
Wayne Roberts |
0:c3ecf7b252a3 | 99 | current.sf = sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 100 | set_symb_timeout(); |
Wayne Roberts |
0:c3ecf7b252a3 | 101 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 102 | |
Wayne Roberts |
0:c3ecf7b252a3 | 103 | conf0.octet = Radio::radio.readReg(REG_ADDR_LORA_CONFIG0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 104 | mpLORA.lora.spreadingFactor = conf0.bits.modem_sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 105 | pc.printf("sf%u\r\n", conf0.bits.modem_sf); |
Wayne Roberts |
0:c3ecf7b252a3 | 106 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 107 | |
Wayne Roberts |
0:c3ecf7b252a3 | 108 | void cmd_bw(uint8_t argsAt) |
Wayne Roberts |
0:c3ecf7b252a3 | 109 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 110 | unsigned n; |
Wayne Roberts |
0:c3ecf7b252a3 | 111 | float khz; |
Wayne Roberts |
0:c3ecf7b252a3 | 112 | loraConfig0_t conf0; |
Wayne Roberts |
0:c3ecf7b252a3 | 113 | |
Wayne Roberts |
0:c3ecf7b252a3 | 114 | if (sscanf(pcbuf + argsAt, "%f", &khz) == 1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 115 | int sidx = -1; |
Wayne Roberts |
0:c3ecf7b252a3 | 116 | float min_diff = 9999; |
Wayne Roberts |
0:c3ecf7b252a3 | 117 | Radio::Standby(); |
Wayne Roberts |
0:c3ecf7b252a3 | 118 | wait(0.02); |
Wayne Roberts |
0:c3ecf7b252a3 | 119 | |
Wayne Roberts |
0:c3ecf7b252a3 | 120 | for (n = 0; lora_bws[n] > 0; n++) { |
Wayne Roberts |
0:c3ecf7b252a3 | 121 | float diff = fabs(lora_bws[n] - khz); |
Wayne Roberts |
0:c3ecf7b252a3 | 122 | if (diff < min_diff) { |
Wayne Roberts |
0:c3ecf7b252a3 | 123 | sidx = n; |
Wayne Roberts |
0:c3ecf7b252a3 | 124 | min_diff = diff; |
Wayne Roberts |
0:c3ecf7b252a3 | 125 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 126 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 127 | if (sidx == -1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 128 | pc.printf("bw not found\r\n"); |
Wayne Roberts |
0:c3ecf7b252a3 | 129 | return; |
Wayne Roberts |
0:c3ecf7b252a3 | 130 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 131 | |
Wayne Roberts |
0:c3ecf7b252a3 | 132 | mpLORA.lora.bandwidth = loraBWs[sidx]; |
Wayne Roberts |
0:c3ecf7b252a3 | 133 | Radio::radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, 0, mpLORA.buf); |
Wayne Roberts |
0:c3ecf7b252a3 | 134 | |
Wayne Roberts |
0:c3ecf7b252a3 | 135 | wait(0.02); |
Wayne Roberts |
0:c3ecf7b252a3 | 136 | set_symb_timeout(); |
Wayne Roberts |
0:c3ecf7b252a3 | 137 | Radio::Rx(0); |
Wayne Roberts |
0:c3ecf7b252a3 | 138 | |
Wayne Roberts |
0:c3ecf7b252a3 | 139 | current.bwKHz = khz; |
Wayne Roberts |
0:c3ecf7b252a3 | 140 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 141 | |
Wayne Roberts |
0:c3ecf7b252a3 | 142 | conf0.octet = Radio::radio.readReg(REG_ADDR_LORA_CONFIG0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 143 | mpLORA.lora.bandwidth = conf0.bits.modem_bw; |
Wayne Roberts |
0:c3ecf7b252a3 | 144 | for (n = 0; n < sizeof(loraBWs); n++) { |
Wayne Roberts |
0:c3ecf7b252a3 | 145 | if (conf0.bits.modem_bw == loraBWs[n]) { |
Wayne Roberts |
0:c3ecf7b252a3 | 146 | pc.printf("%.1fKHz\r\n", lora_bws[n]); |
Wayne Roberts |
0:c3ecf7b252a3 | 147 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 148 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 149 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 150 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 151 | |
Wayne Roberts |
0:c3ecf7b252a3 | 152 | void radio_readChip() |
Wayne Roberts |
0:c3ecf7b252a3 | 153 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 154 | #if 0 |
Wayne Roberts |
0:c3ecf7b252a3 | 155 | bwSel_t bwSel; |
Wayne Roberts |
0:c3ecf7b252a3 | 156 | shapeCfg_t shapeCfg; |
Wayne Roberts |
0:c3ecf7b252a3 | 157 | unsigned d = radio.readReg(REG_ADDR_BITRATE, 3); |
Wayne Roberts |
0:c3ecf7b252a3 | 158 | pc.printf("%06x:%u->", d ,d); |
Wayne Roberts |
0:c3ecf7b252a3 | 159 | pc.printf("bitrate %ubps\r\n", (32 * XTAL_FREQ_HZ) / d); |
Wayne Roberts |
0:c3ecf7b252a3 | 160 | mpFSK.gfsk.bitrateHi = d >> 16; |
Wayne Roberts |
0:c3ecf7b252a3 | 161 | mpFSK.gfsk.bitrateMid = d >> 8; |
Wayne Roberts |
0:c3ecf7b252a3 | 162 | mpFSK.gfsk.bitrateLo = d; |
Wayne Roberts |
0:c3ecf7b252a3 | 163 | |
Wayne Roberts |
0:c3ecf7b252a3 | 164 | d = radio.readReg(REG_ADDR_FREQDEV, 3); |
Wayne Roberts |
0:c3ecf7b252a3 | 165 | pc.printf("fdev %fKHz\r\n", d / KHZ_TO_FRF); |
Wayne Roberts |
0:c3ecf7b252a3 | 166 | mpFSK.gfsk.fdevHi = d >> 16; |
Wayne Roberts |
0:c3ecf7b252a3 | 167 | mpFSK.gfsk.fdevMid = d >> 8; |
Wayne Roberts |
0:c3ecf7b252a3 | 168 | mpFSK.gfsk.fdevLo = d; |
Wayne Roberts |
0:c3ecf7b252a3 | 169 | |
Wayne Roberts |
0:c3ecf7b252a3 | 170 | shapeCfg.octet = radio.readReg(REG_ADDR_SHAPECFG, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 171 | mpFSK.gfsk.PulseShape = shapeCfg.octet; |
Wayne Roberts |
0:c3ecf7b252a3 | 172 | |
Wayne Roberts |
0:c3ecf7b252a3 | 173 | bwSel.octet = radio.readReg(REG_ADDR_BWSEL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 174 | // GFSK_RX_BW_* |
Wayne Roberts |
0:c3ecf7b252a3 | 175 | pc.printf("bwsSel:%02x\r\n", bwSel.octet); |
Wayne Roberts |
0:c3ecf7b252a3 | 176 | mpFSK.gfsk.bandwidth = bwSel.octet; |
Wayne Roberts |
0:c3ecf7b252a3 | 177 | |
Wayne Roberts |
0:c3ecf7b252a3 | 178 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 179 | unsigned n = radio.readReg(REG_ADDR_FSK_PREAMBLE_TXLEN , 2); |
Wayne Roberts |
0:c3ecf7b252a3 | 180 | ppFSK.gfsk.PreambleLengthHi = n << 8; // param1 |
Wayne Roberts |
0:c3ecf7b252a3 | 181 | ppFSK.gfsk.PreambleLengthLo = n;// param2 |
Wayne Roberts |
0:c3ecf7b252a3 | 182 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 183 | |
Wayne Roberts |
0:c3ecf7b252a3 | 184 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 185 | pktCtrl1_t pktCtrl1; |
Wayne Roberts |
0:c3ecf7b252a3 | 186 | pktCtrl1.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL1, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 187 | ppFSK.gfsk.PreambleDetectorLength = pktCtrl1.octet & 0x07; // param3 |
Wayne Roberts |
0:c3ecf7b252a3 | 188 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 189 | |
Wayne Roberts |
0:c3ecf7b252a3 | 190 | |
Wayne Roberts |
0:c3ecf7b252a3 | 191 | ppFSK.gfsk.SyncWordLength = radio.readReg(REG_ADDR_FSK_SYNC_LEN, 1);// param4 |
Wayne Roberts |
0:c3ecf7b252a3 | 192 | ppFSK.gfsk.AddrComp = radio.readReg(REG_ADDR_NODEADDRCOMP, 1);// param5 |
Wayne Roberts |
0:c3ecf7b252a3 | 193 | |
Wayne Roberts |
0:c3ecf7b252a3 | 194 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 195 | pktCtrl0_t pktCtrl0; |
Wayne Roberts |
0:c3ecf7b252a3 | 196 | pktCtrl0.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 197 | ppFSK.gfsk.PacketType = pktCtrl0.bits.pkt_len_format; // param6 |
Wayne Roberts |
0:c3ecf7b252a3 | 198 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 199 | |
Wayne Roberts |
0:c3ecf7b252a3 | 200 | ppFSK.gfsk.PayloadLength = radio.readReg(REG_ADDR_FSK_PAYLOAD_LEN, 1);// param7 |
Wayne Roberts |
0:c3ecf7b252a3 | 201 | |
Wayne Roberts |
0:c3ecf7b252a3 | 202 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 203 | pktCtrl2_t pktCtrl2; |
Wayne Roberts |
0:c3ecf7b252a3 | 204 | pktCtrl2.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL2, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 205 | ppFSK.gfsk.CRCType = pktCtrl2.octet & 0x7; // param8 |
Wayne Roberts |
0:c3ecf7b252a3 | 206 | ppFSK.gfsk.Whitening = pktCtrl2.bits.whit_enable; // param9 |
Wayne Roberts |
0:c3ecf7b252a3 | 207 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 208 | #endif /* if 0 */ |
Wayne Roberts |
0:c3ecf7b252a3 | 209 | |
Wayne Roberts |
0:c3ecf7b252a3 | 210 | /*******************************/ |
Wayne Roberts |
0:c3ecf7b252a3 | 211 | |
Wayne Roberts |
0:c3ecf7b252a3 | 212 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 213 | loraConfig0_t conf0; |
Wayne Roberts |
0:c3ecf7b252a3 | 214 | conf0.octet = Radio::radio.readReg(REG_ADDR_LORA_CONFIG0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 215 | pc.printf("LoRa bw%u sf%u ", conf0.bits.modem_bw, conf0.bits.modem_sf); |
Wayne Roberts |
0:c3ecf7b252a3 | 216 | mpLORA.lora.spreadingFactor = conf0.bits.modem_sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 217 | mpLORA.lora.bandwidth = conf0.bits.modem_bw; |
Wayne Roberts |
0:c3ecf7b252a3 | 218 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 219 | |
Wayne Roberts |
0:c3ecf7b252a3 | 220 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 221 | loraConfig1_t conf1; |
Wayne Roberts |
0:c3ecf7b252a3 | 222 | conf1.octet = Radio::radio.readReg(REG_ADDR_LORA_CONFIG1, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 223 | mpLORA.lora.LowDatarateOptimize = conf1.bits.ppm_offset; |
Wayne Roberts |
0:c3ecf7b252a3 | 224 | ppLORA.lora.HeaderType = conf1.bits.implicit_header; |
Wayne Roberts |
0:c3ecf7b252a3 | 225 | ppLORA.lora.InvertIQ = conf1.bits.rx_invert_iq; |
Wayne Roberts |
0:c3ecf7b252a3 | 226 | mpLORA.lora.codingRate = conf1.bits.tx_coding_rate; |
Wayne Roberts |
0:c3ecf7b252a3 | 227 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 228 | |
Wayne Roberts |
0:c3ecf7b252a3 | 229 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 230 | loraConfig2_t conf2; |
Wayne Roberts |
0:c3ecf7b252a3 | 231 | conf2.octet = Radio::radio.readReg(REG_ADDR_LORA_CONFIG2, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 232 | ppLORA.lora.CRCType = conf2.bits.tx_payload_crc16_en; |
Wayne Roberts |
0:c3ecf7b252a3 | 233 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 234 | |
Wayne Roberts |
0:c3ecf7b252a3 | 235 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 236 | uint32_t val = Radio::radio.readReg(REG_ADDR_LORA_PREAMBLE_SYMBNB, 2); |
Wayne Roberts |
0:c3ecf7b252a3 | 237 | ppLORA.lora.PreambleLengthHi = val >> 8; |
Wayne Roberts |
0:c3ecf7b252a3 | 238 | ppLORA.lora.PreambleLengthLo = val; |
Wayne Roberts |
0:c3ecf7b252a3 | 239 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 240 | |
Wayne Roberts |
0:c3ecf7b252a3 | 241 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 242 | AnaCtrl6_t AnaCtrl6; |
Wayne Roberts |
0:c3ecf7b252a3 | 243 | AnaCtrl7_t AnaCtrl7; |
Wayne Roberts |
0:c3ecf7b252a3 | 244 | PaCtrl1b_t PaCtrl1b; |
Wayne Roberts |
0:c3ecf7b252a3 | 245 | |
Wayne Roberts |
0:c3ecf7b252a3 | 246 | AnaCtrl6.octet = Radio::radio.readReg(REG_ADDR_ANACTRL6, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 247 | pa_config_buf[0] = AnaCtrl6.bits.pa_dctrim_select_ana; // paDutyCycle |
Wayne Roberts |
0:c3ecf7b252a3 | 248 | |
Wayne Roberts |
0:c3ecf7b252a3 | 249 | AnaCtrl7.octet = Radio::radio.readReg(REG_ADDR_ANACTRL7, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 250 | pa_config_buf[1] = AnaCtrl7.bits.pa_hp_sel_ana; // hpMax |
Wayne Roberts |
0:c3ecf7b252a3 | 251 | |
Wayne Roberts |
0:c3ecf7b252a3 | 252 | PaCtrl1b.octet = Radio::radio.readReg(REG_ADDR_PA_CTRL1B, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 253 | pa_config_buf[2] = PaCtrl1b.bits.tx_mode_bat; // deviceSel |
Wayne Roberts |
0:c3ecf7b252a3 | 254 | |
Wayne Roberts |
0:c3ecf7b252a3 | 255 | pa_config_buf[3] = 1; // paLut |
Wayne Roberts |
0:c3ecf7b252a3 | 256 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 257 | |
Wayne Roberts |
0:c3ecf7b252a3 | 258 | /* { |
Wayne Roberts |
0:c3ecf7b252a3 | 259 | cadParams[0] = radio.readReg(REG_ADDR_LORA_CONFIG9, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 260 | cadParams[0] >>= 5; |
Wayne Roberts |
0:c3ecf7b252a3 | 261 | |
Wayne Roberts |
0:c3ecf7b252a3 | 262 | cadParams[1] = radio.readReg(REG_ADDR_LORA_CAD_PN_RATIO, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 263 | cadParams[2] = radio.readReg(REG_ADDR_LORA_CAD_MINPEAK, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 264 | }*/ |
Wayne Roberts |
0:c3ecf7b252a3 | 265 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 266 | |
Wayne Roberts |
0:c3ecf7b252a3 | 267 | #endif /* SX126x_H */ |