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_sx128x.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 SX128x_H |
Wayne Roberts |
0:c3ecf7b252a3 | 3 | |
Wayne Roberts |
0:c3ecf7b252a3 | 4 | #define TX_PWR_OFFSET 18 |
Wayne Roberts |
0:c3ecf7b252a3 | 5 | |
Wayne Roberts |
0:c3ecf7b252a3 | 6 | static uint8_t tx_param_buf[2]; |
Wayne Roberts |
0:c3ecf7b252a3 | 7 | static ModulationParams_t mpLORA; |
Wayne Roberts |
0:c3ecf7b252a3 | 8 | static PacketParams_t ppLORA; |
Wayne Roberts |
0:c3ecf7b252a3 | 9 | static LoRaPktPar0_t LoRaPktPar0; |
Wayne Roberts |
0:c3ecf7b252a3 | 10 | |
Wayne Roberts |
0:c3ecf7b252a3 | 11 | void tx_dbm_print() |
Wayne Roberts |
0:c3ecf7b252a3 | 12 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 13 | PaPwrCtrl_t PaPwrCtrl; |
Wayne Roberts |
0:c3ecf7b252a3 | 14 | |
Wayne Roberts |
0:c3ecf7b252a3 | 15 | PaPwrCtrl.octet = Radio::radio.readReg(REG_ADDR_PA_PWR_CTRL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 16 | pc.printf("%ddBm ", PaPwrCtrl.bits.tx_pwr - TX_PWR_OFFSET); |
Wayne Roberts |
0:c3ecf7b252a3 | 17 | |
Wayne Roberts |
0:c3ecf7b252a3 | 18 | tx_param_buf[0] = PaPwrCtrl.bits.tx_pwr; |
Wayne Roberts |
0:c3ecf7b252a3 | 19 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 20 | |
Wayne Roberts |
0:c3ecf7b252a3 | 21 | static const unsigned lora_bws[] = { |
Wayne Roberts |
0:c3ecf7b252a3 | 22 | 50, // 0 |
Wayne Roberts |
0:c3ecf7b252a3 | 23 | 100, // 1 |
Wayne Roberts |
0:c3ecf7b252a3 | 24 | 200, // 2 |
Wayne Roberts |
0:c3ecf7b252a3 | 25 | 400, // 3 |
Wayne Roberts |
0:c3ecf7b252a3 | 26 | 800, // 4 |
Wayne Roberts |
0:c3ecf7b252a3 | 27 | 1600 // 5 |
Wayne Roberts |
0:c3ecf7b252a3 | 28 | }; |
Wayne Roberts |
0:c3ecf7b252a3 | 29 | |
Wayne Roberts |
0:c3ecf7b252a3 | 30 | static const unsigned loraBWs[] = { |
Wayne Roberts |
0:c3ecf7b252a3 | 31 | LORA_BW_50, // 0 50 |
Wayne Roberts |
0:c3ecf7b252a3 | 32 | LORA_BW_100, // 1 100 |
Wayne Roberts |
0:c3ecf7b252a3 | 33 | LORA_BW_200, // 2 200 |
Wayne Roberts |
0:c3ecf7b252a3 | 34 | LORA_BW_400, // 3 400 |
Wayne Roberts |
0:c3ecf7b252a3 | 35 | LORA_BW_800, // 4 800 |
Wayne Roberts |
0:c3ecf7b252a3 | 36 | LORA_BW_1600 // 5 1600 |
Wayne Roberts |
0:c3ecf7b252a3 | 37 | }; |
Wayne Roberts |
0:c3ecf7b252a3 | 38 | |
Wayne Roberts |
0:c3ecf7b252a3 | 39 | void print_lora_status() |
Wayne Roberts |
0:c3ecf7b252a3 | 40 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 41 | float MHz; |
Wayne Roberts |
0:c3ecf7b252a3 | 42 | status_t status; |
Wayne Roberts |
0:c3ecf7b252a3 | 43 | |
Wayne Roberts |
0:c3ecf7b252a3 | 44 | tx_dbm_print(); |
Wayne Roberts |
0:c3ecf7b252a3 | 45 | |
Wayne Roberts |
0:c3ecf7b252a3 | 46 | status.octet = Radio::radio.xfer(OPCODE_GET_STATUS, 0, 0, NULL); |
Wayne Roberts |
0:c3ecf7b252a3 | 47 | switch (status.bits.chipMode) { |
Wayne Roberts |
0:c3ecf7b252a3 | 48 | case 2: pc.printf("STDBY_RC"); break; // STDBY_RC |
Wayne Roberts |
0:c3ecf7b252a3 | 49 | case 3: pc.printf("STDBY_XOSC"); break; //STDBY_XOSC |
Wayne Roberts |
0:c3ecf7b252a3 | 50 | case 4: pc.printf("FS"); break; //FS |
Wayne Roberts |
0:c3ecf7b252a3 | 51 | case 5: pc.printf("RX"); break; // RX |
Wayne Roberts |
0:c3ecf7b252a3 | 52 | case 6: pc.printf("TX"); break; // TX |
Wayne Roberts |
0:c3ecf7b252a3 | 53 | default: pc.printf("<%u>", status.bits.chipMode); break; |
Wayne Roberts |
0:c3ecf7b252a3 | 54 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 55 | pc.printf("\t"); |
Wayne Roberts |
0:c3ecf7b252a3 | 56 | |
Wayne Roberts |
0:c3ecf7b252a3 | 57 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 58 | IrqFlags_t irqFlags; |
Wayne Roberts |
0:c3ecf7b252a3 | 59 | uint8_t buf[6]; |
Wayne Roberts |
0:c3ecf7b252a3 | 60 | Radio::radio.xfer(OPCODE_GET_IRQ_STATUS, 0, 3, buf); |
Wayne Roberts |
0:c3ecf7b252a3 | 61 | status.octet = buf[0]; |
Wayne Roberts |
0:c3ecf7b252a3 | 62 | irqFlags.word = buf[1] << 8; |
Wayne Roberts |
0:c3ecf7b252a3 | 63 | irqFlags.word |= buf[2]; |
Wayne Roberts |
0:c3ecf7b252a3 | 64 | pc.printf(" irq:%04x ", irqFlags.word); |
Wayne Roberts |
0:c3ecf7b252a3 | 65 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 66 | |
Wayne Roberts |
0:c3ecf7b252a3 | 67 | LoRaPktPar0.octet = Radio::radio.readReg(REG_ADDR_LORA_PKTPAR0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 68 | |
Wayne Roberts |
0:c3ecf7b252a3 | 69 | pc.printf("%uKHz ", lora_bws[LoRaPktPar0.bits.modem_bw]); |
Wayne Roberts |
0:c3ecf7b252a3 | 70 | pc.printf("sf%u", LoRaPktPar0.bits.modem_sf); |
Wayne Roberts |
0:c3ecf7b252a3 | 71 | |
Wayne Roberts |
0:c3ecf7b252a3 | 72 | MHz = Radio::radio.getMHz(); |
Wayne Roberts |
0:c3ecf7b252a3 | 73 | pc.printf(" %.3fMHz\r\n", MHz); |
Wayne Roberts |
0:c3ecf7b252a3 | 74 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 75 | |
Wayne Roberts |
0:c3ecf7b252a3 | 76 | void cmd_sf(uint8_t argsAt) |
Wayne Roberts |
0:c3ecf7b252a3 | 77 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 78 | unsigned sf; |
Wayne Roberts |
0:c3ecf7b252a3 | 79 | if (sscanf(pcbuf + argsAt, "%u", &sf) == 1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 80 | mpLORA.lora.spreadingFactor = sf << 4; |
Wayne Roberts |
0:c3ecf7b252a3 | 81 | Radio::radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf); |
Wayne Roberts |
0:c3ecf7b252a3 | 82 | set_symb_timeout(); |
Wayne Roberts |
0:c3ecf7b252a3 | 83 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 84 | |
Wayne Roberts |
0:c3ecf7b252a3 | 85 | LoRaPktPar0.octet = Radio::radio.readReg(REG_ADDR_LORA_PKTPAR0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 86 | pc.printf("sf%u\r\n", LoRaPktPar0.bits.modem_sf); |
Wayne Roberts |
0:c3ecf7b252a3 | 87 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 88 | |
Wayne Roberts |
0:c3ecf7b252a3 | 89 | void cmd_frf(uint8_t argsAt) |
Wayne Roberts |
0:c3ecf7b252a3 | 90 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 91 | float MHz; |
Wayne Roberts |
0:c3ecf7b252a3 | 92 | |
Wayne Roberts |
0:c3ecf7b252a3 | 93 | if (sscanf(pcbuf + argsAt, "%f", &MHz) == 1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 94 | Radio::radio.setMHz(MHz); |
Wayne Roberts |
0:c3ecf7b252a3 | 95 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 96 | MHz = Radio::radio.getMHz(); |
Wayne Roberts |
0:c3ecf7b252a3 | 97 | pc.printf("%.3fMHz\r\n", MHz); |
Wayne Roberts |
0:c3ecf7b252a3 | 98 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 99 | |
Wayne Roberts |
0:c3ecf7b252a3 | 100 | void cmd_bw(uint8_t argsAt) |
Wayne Roberts |
0:c3ecf7b252a3 | 101 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 102 | unsigned n; |
Wayne Roberts |
0:c3ecf7b252a3 | 103 | float khz; |
Wayne Roberts |
0:c3ecf7b252a3 | 104 | |
Wayne Roberts |
0:c3ecf7b252a3 | 105 | if (sscanf(pcbuf + argsAt, "%f", &khz) == 1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 106 | int sidx = -1; |
Wayne Roberts |
0:c3ecf7b252a3 | 107 | float min_diff = 9999; |
Wayne Roberts |
0:c3ecf7b252a3 | 108 | Radio::Standby(); |
Wayne Roberts |
0:c3ecf7b252a3 | 109 | wait(0.02); |
Wayne Roberts |
0:c3ecf7b252a3 | 110 | |
Wayne Roberts |
0:c3ecf7b252a3 | 111 | for (n = 0; lora_bws[n] > 0; n++) { |
Wayne Roberts |
0:c3ecf7b252a3 | 112 | float diff = fabs(lora_bws[n] - khz); |
Wayne Roberts |
0:c3ecf7b252a3 | 113 | if (diff < min_diff) { |
Wayne Roberts |
0:c3ecf7b252a3 | 114 | sidx = n; |
Wayne Roberts |
0:c3ecf7b252a3 | 115 | min_diff = diff; |
Wayne Roberts |
0:c3ecf7b252a3 | 116 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 117 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 118 | if (sidx == -1) { |
Wayne Roberts |
0:c3ecf7b252a3 | 119 | pc.printf("bw not found\r\n"); |
Wayne Roberts |
0:c3ecf7b252a3 | 120 | return; |
Wayne Roberts |
0:c3ecf7b252a3 | 121 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 122 | |
Wayne Roberts |
0:c3ecf7b252a3 | 123 | mpLORA.lora.bandwidth = loraBWs[sidx]; |
Wayne Roberts |
0:c3ecf7b252a3 | 124 | Radio::radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf); |
Wayne Roberts |
0:c3ecf7b252a3 | 125 | |
Wayne Roberts |
0:c3ecf7b252a3 | 126 | wait(0.02); |
Wayne Roberts |
0:c3ecf7b252a3 | 127 | set_symb_timeout(); |
Wayne Roberts |
0:c3ecf7b252a3 | 128 | Radio::Rx(0); |
Wayne Roberts |
0:c3ecf7b252a3 | 129 | |
Wayne Roberts |
0:c3ecf7b252a3 | 130 | current.bwKHz = khz; |
Wayne Roberts |
0:c3ecf7b252a3 | 131 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 132 | |
Wayne Roberts |
0:c3ecf7b252a3 | 133 | LoRaPktPar0.octet = Radio::radio.readReg(REG_ADDR_LORA_PKTPAR0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 134 | pc.printf("%uKHz\r\n", lora_bws[LoRaPktPar0.bits.modem_bw]); |
Wayne Roberts |
0:c3ecf7b252a3 | 135 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 136 | |
Wayne Roberts |
0:c3ecf7b252a3 | 137 | void radio_readChip() |
Wayne Roberts |
0:c3ecf7b252a3 | 138 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 139 | //uint8_t reg8; |
Wayne Roberts |
0:c3ecf7b252a3 | 140 | |
Wayne Roberts |
0:c3ecf7b252a3 | 141 | #if 0 |
Wayne Roberts |
0:c3ecf7b252a3 | 142 | reg8 = Radio::radio.readReg(REG_ADDR_PKTCTRL0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 143 | ppGFSK.gfskFLRC.HeaderType = reg8 & 0x20; |
Wayne Roberts |
0:c3ecf7b252a3 | 144 | ppFLRC.gfskFLRC.HeaderType = reg8 & 0x20; |
Wayne Roberts |
0:c3ecf7b252a3 | 145 | |
Wayne Roberts |
0:c3ecf7b252a3 | 146 | reg8 = Radio::radio.readReg(REG_ADDR_PKTCTRL1, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 147 | ppGFSK.gfskFLRC.PreambleLength = reg8 & 0x70; |
Wayne Roberts |
0:c3ecf7b252a3 | 148 | ppFLRC.gfskFLRC.PreambleLength = reg8 & 0x70; |
Wayne Roberts |
0:c3ecf7b252a3 | 149 | ppGFSK.gfskFLRC.SyncWordLength = reg8 & 0x0e; |
Wayne Roberts |
0:c3ecf7b252a3 | 150 | ppFLRC.gfskFLRC.SyncWordLength = reg8 & 0x06; |
Wayne Roberts |
0:c3ecf7b252a3 | 151 | if (ppFLRC.gfskFLRC.SyncWordLength == 0x06) |
Wayne Roberts |
0:c3ecf7b252a3 | 152 | ppFLRC.gfskFLRC.SyncWordLength = FLRC_SYNC_WORD_LEN_P32S; |
Wayne Roberts |
0:c3ecf7b252a3 | 153 | |
Wayne Roberts |
0:c3ecf7b252a3 | 154 | reg8 = Radio::radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 155 | ppGFSK.gfskFLRC.SyncWordMatch = reg8 & 0x70; |
Wayne Roberts |
0:c3ecf7b252a3 | 156 | ppFLRC.gfskFLRC.SyncWordMatch = reg8 & 0x70; |
Wayne Roberts |
0:c3ecf7b252a3 | 157 | |
Wayne Roberts |
0:c3ecf7b252a3 | 158 | reg8 = Radio::radio.readReg(REG_ADDR_PAYLOAD_LEN, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 159 | ppGFSK.gfskFLRC.PayloadLength = reg8; |
Wayne Roberts |
0:c3ecf7b252a3 | 160 | ppFLRC.gfskFLRC.PayloadLength = reg8; |
Wayne Roberts |
0:c3ecf7b252a3 | 161 | |
Wayne Roberts |
0:c3ecf7b252a3 | 162 | reg8 = Radio::radio.readReg(REG_ADDR_PKT_TX_HEADER, 1); // TODO hi bit of payload length |
Wayne Roberts |
0:c3ecf7b252a3 | 163 | ppBLE.ble.ConnectionState = reg8 & 0xe0; |
Wayne Roberts |
0:c3ecf7b252a3 | 164 | ppBLE.ble.BleTestPayload = reg8 & 0x1c; |
Wayne Roberts |
0:c3ecf7b252a3 | 165 | |
Wayne Roberts |
0:c3ecf7b252a3 | 166 | reg8 = Radio::radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 167 | ppBLE.ble.CrcLength = reg8 & 0x30; |
Wayne Roberts |
0:c3ecf7b252a3 | 168 | ppBLE.ble.Whitening = reg8 & 0x08; |
Wayne Roberts |
0:c3ecf7b252a3 | 169 | ppGFSK.gfskFLRC.CRCLength = reg8 & 0x30; |
Wayne Roberts |
0:c3ecf7b252a3 | 170 | ppFLRC.gfskFLRC.CRCLength = reg8 & 0x30; |
Wayne Roberts |
0:c3ecf7b252a3 | 171 | ppGFSK.gfskFLRC.Whitening = reg8 & 0x08; |
Wayne Roberts |
0:c3ecf7b252a3 | 172 | ppFLRC.gfskFLRC.Whitening = reg8 & 0x08; |
Wayne Roberts |
0:c3ecf7b252a3 | 173 | #endif /* if 0 */ |
Wayne Roberts |
0:c3ecf7b252a3 | 174 | |
Wayne Roberts |
0:c3ecf7b252a3 | 175 | LoRaPktPar0.octet = Radio::radio.readReg(REG_ADDR_LORA_PKTPAR0, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 176 | switch (LoRaPktPar0.bits.modem_bw) { |
Wayne Roberts |
0:c3ecf7b252a3 | 177 | case 2: mpLORA.lora.bandwidth = LORA_BW_200; break; |
Wayne Roberts |
0:c3ecf7b252a3 | 178 | case 3: mpLORA.lora.bandwidth = LORA_BW_400; break; |
Wayne Roberts |
0:c3ecf7b252a3 | 179 | case 4: mpLORA.lora.bandwidth = LORA_BW_800; break; |
Wayne Roberts |
0:c3ecf7b252a3 | 180 | case 5: mpLORA.lora.bandwidth = LORA_BW_1600; break; |
Wayne Roberts |
0:c3ecf7b252a3 | 181 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 182 | mpLORA.lora.spreadingFactor = LoRaPktPar0.bits.modem_sf << 4; |
Wayne Roberts |
0:c3ecf7b252a3 | 183 | |
Wayne Roberts |
0:c3ecf7b252a3 | 184 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 185 | LoRaPktPar1_t LoRaPktPar1; |
Wayne Roberts |
0:c3ecf7b252a3 | 186 | LoRaPktPar1.octet = Radio::radio.readReg(REG_ADDR_LORA_PKTPAR1, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 187 | mpLORA.lora.codingRate = LoRaPktPar1.bits.coding_rate; |
Wayne Roberts |
0:c3ecf7b252a3 | 188 | ppLORA.lora.InvertIQ = LoRaPktPar1.bits.rxinvert_iq ? LORA_IQ_INVERTED : LORA_IQ_STD; |
Wayne Roberts |
0:c3ecf7b252a3 | 189 | ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header ? IMPLICIT_HEADER : EXPLICIT_HEADER; |
Wayne Roberts |
0:c3ecf7b252a3 | 190 | // LoRaPktPar1.bits.ppm_offset |
Wayne Roberts |
0:c3ecf7b252a3 | 191 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 192 | |
Wayne Roberts |
0:c3ecf7b252a3 | 193 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 194 | LoRaPreambleReg_t LoRaPreambleReg; |
Wayne Roberts |
0:c3ecf7b252a3 | 195 | LoRaPreambleReg.octet = Radio::radio.readReg(REG_ADDR_LORA_PREAMBLE, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 196 | ppLORA.lora.PreambleLength = LoRaPreambleReg.bits.preamble_symb1_nb * (1 << LoRaPreambleReg.bits.preamble_symb_nb_exp); |
Wayne Roberts |
0:c3ecf7b252a3 | 197 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 198 | ppLORA.lora.PayloadLength = Radio::radio.readReg(REG_ADDR_LORA_TX_PAYLOAD_LENGTH, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 199 | |
Wayne Roberts |
0:c3ecf7b252a3 | 200 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 201 | LoRaLrCtl_t LoRaLrCtl; |
Wayne Roberts |
0:c3ecf7b252a3 | 202 | LoRaLrCtl.octet = Radio::radio.readReg(REG_ADDR_LORA_LRCTL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 203 | ppLORA.lora.crc = LoRaLrCtl.octet & 0x20; // LoRaLrCtl.bits.crc_en |
Wayne Roberts |
0:c3ecf7b252a3 | 204 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 205 | |
Wayne Roberts |
0:c3ecf7b252a3 | 206 | #if 0 |
Wayne Roberts |
0:c3ecf7b252a3 | 207 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 208 | RegRxBw_t RegRxBw; |
Wayne Roberts |
0:c3ecf7b252a3 | 209 | unsigned bps; |
Wayne Roberts |
0:c3ecf7b252a3 | 210 | FloraPreambleHi_t FloraPreambleHi; |
Wayne Roberts |
0:c3ecf7b252a3 | 211 | float mi, fdev_hz; |
Wayne Roberts |
0:c3ecf7b252a3 | 212 | unsigned freqDev; |
Wayne Roberts |
0:c3ecf7b252a3 | 213 | FskModDfH_t FskModDfH; |
Wayne Roberts |
0:c3ecf7b252a3 | 214 | FskModDfH.octet = radio.readReg(REG_ADDR_FSK_MODDFH, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 215 | freqDev = FskModDfH.bits.freqDev; |
Wayne Roberts |
0:c3ecf7b252a3 | 216 | freqDev <<= 8; |
Wayne Roberts |
0:c3ecf7b252a3 | 217 | freqDev |= radio.readReg(REG_ADDR_FSK_MODDFL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 218 | //pc.printf("freqDev %x, %x\r\n", freqDev, freqDev); |
Wayne Roberts |
0:c3ecf7b252a3 | 219 | fdev_hz = freqDev * PLL_STEP_HZ; |
Wayne Roberts |
0:c3ecf7b252a3 | 220 | //pc.printf("fdev hz:%f\r\n", fdev_hz); |
Wayne Roberts |
0:c3ecf7b252a3 | 221 | |
Wayne Roberts |
0:c3ecf7b252a3 | 222 | FloraPreambleHi.octet = radio.readReg(REG_ADDR_FLORA_PREAMBLE_HI, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 223 | switch (FloraPreambleHi.bits.data_rate) { |
Wayne Roberts |
0:c3ecf7b252a3 | 224 | case 0: |
Wayne Roberts |
0:c3ecf7b252a3 | 225 | bps = 2.0e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 226 | //mpFLRC.flrc.bitrateBandwidth = ??; // 2.6 |
Wayne Roberts |
0:c3ecf7b252a3 | 227 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 228 | case 1: |
Wayne Roberts |
0:c3ecf7b252a3 | 229 | bps = 1.6e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 230 | //mpFLRC.flrc.bitrateBandwidth = ??; // 2.08 |
Wayne Roberts |
0:c3ecf7b252a3 | 231 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 232 | case 2: |
Wayne Roberts |
0:c3ecf7b252a3 | 233 | bps = 1.0e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 234 | mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_300_BW_1_2; // 1.3 |
Wayne Roberts |
0:c3ecf7b252a3 | 235 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 236 | case 3: |
Wayne Roberts |
0:c3ecf7b252a3 | 237 | bps = 0.8e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 238 | mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_000_BW_1_2; // 1.04 |
Wayne Roberts |
0:c3ecf7b252a3 | 239 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 240 | case 4: |
Wayne Roberts |
0:c3ecf7b252a3 | 241 | bps = 0.5e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 242 | mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_650_BW_0_6; // 0.65 |
Wayne Roberts |
0:c3ecf7b252a3 | 243 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 244 | case 5: |
Wayne Roberts |
0:c3ecf7b252a3 | 245 | bps = 0.4e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 246 | mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_520_BW_0_6; // 0.52 |
Wayne Roberts |
0:c3ecf7b252a3 | 247 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 248 | case 6: |
Wayne Roberts |
0:c3ecf7b252a3 | 249 | bps = 0.25e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 250 | mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_325_BW_0_3; // 0.325 |
Wayne Roberts |
0:c3ecf7b252a3 | 251 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 252 | case 7: |
Wayne Roberts |
0:c3ecf7b252a3 | 253 | bps = 0.125e6; |
Wayne Roberts |
0:c3ecf7b252a3 | 254 | mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_260_BW_0_3; // 0.26 |
Wayne Roberts |
0:c3ecf7b252a3 | 255 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 256 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 257 | |
Wayne Roberts |
0:c3ecf7b252a3 | 258 | mi = (fdev_hz * 2.0) / bps; |
Wayne Roberts |
0:c3ecf7b252a3 | 259 | if (mi > 0.35) { |
Wayne Roberts |
0:c3ecf7b252a3 | 260 | mi -= 0.5; |
Wayne Roberts |
0:c3ecf7b252a3 | 261 | mi /= 0.25; |
Wayne Roberts |
0:c3ecf7b252a3 | 262 | mpBLE_GFSK.gfskBle.ModulationIndex = ((uint8_t)mi) + 1; |
Wayne Roberts |
0:c3ecf7b252a3 | 263 | } else |
Wayne Roberts |
0:c3ecf7b252a3 | 264 | mpBLE_GFSK.gfskBle.ModulationIndex = 0; |
Wayne Roberts |
0:c3ecf7b252a3 | 265 | |
Wayne Roberts |
0:c3ecf7b252a3 | 266 | RegRxBw.octet = radio.readReg(REG_ADDR_RXBW, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 267 | |
Wayne Roberts |
0:c3ecf7b252a3 | 268 | //pc.printf("rx "); |
Wayne Roberts |
0:c3ecf7b252a3 | 269 | switch (RegRxBw.bits.bw) { |
Wayne Roberts |
0:c3ecf7b252a3 | 270 | case 0: |
Wayne Roberts |
0:c3ecf7b252a3 | 271 | //pc.printf("2.4"); |
Wayne Roberts |
0:c3ecf7b252a3 | 272 | if (FloraPreambleHi.bits.data_rate == 0) |
Wayne Roberts |
0:c3ecf7b252a3 | 273 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_2_000_BW_2_4; |
Wayne Roberts |
0:c3ecf7b252a3 | 274 | if (FloraPreambleHi.bits.data_rate == 1) |
Wayne Roberts |
0:c3ecf7b252a3 | 275 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_600_BW_2_4; |
Wayne Roberts |
0:c3ecf7b252a3 | 276 | if (FloraPreambleHi.bits.data_rate == 2) |
Wayne Roberts |
0:c3ecf7b252a3 | 277 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_2_4; |
Wayne Roberts |
0:c3ecf7b252a3 | 278 | if (FloraPreambleHi.bits.data_rate == 3) |
Wayne Roberts |
0:c3ecf7b252a3 | 279 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_2_4; |
Wayne Roberts |
0:c3ecf7b252a3 | 280 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 281 | case 1: |
Wayne Roberts |
0:c3ecf7b252a3 | 282 | //pc.printf("1.2"); |
Wayne Roberts |
0:c3ecf7b252a3 | 283 | if (FloraPreambleHi.bits.data_rate == 2) |
Wayne Roberts |
0:c3ecf7b252a3 | 284 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_1_2; |
Wayne Roberts |
0:c3ecf7b252a3 | 285 | if (FloraPreambleHi.bits.data_rate == 3) |
Wayne Roberts |
0:c3ecf7b252a3 | 286 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_1_2; |
Wayne Roberts |
0:c3ecf7b252a3 | 287 | if (FloraPreambleHi.bits.data_rate == 4) |
Wayne Roberts |
0:c3ecf7b252a3 | 288 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_1_2; |
Wayne Roberts |
0:c3ecf7b252a3 | 289 | if (FloraPreambleHi.bits.data_rate == 5) |
Wayne Roberts |
0:c3ecf7b252a3 | 290 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_1_2; |
Wayne Roberts |
0:c3ecf7b252a3 | 291 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 292 | case 2: |
Wayne Roberts |
0:c3ecf7b252a3 | 293 | //pc.printf("0.6"); |
Wayne Roberts |
0:c3ecf7b252a3 | 294 | if (FloraPreambleHi.bits.data_rate == 4) |
Wayne Roberts |
0:c3ecf7b252a3 | 295 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_0_6; |
Wayne Roberts |
0:c3ecf7b252a3 | 296 | if (FloraPreambleHi.bits.data_rate == 5) |
Wayne Roberts |
0:c3ecf7b252a3 | 297 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_0_6; |
Wayne Roberts |
0:c3ecf7b252a3 | 298 | if (FloraPreambleHi.bits.data_rate == 6) |
Wayne Roberts |
0:c3ecf7b252a3 | 299 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_6; |
Wayne Roberts |
0:c3ecf7b252a3 | 300 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 301 | case 3: |
Wayne Roberts |
0:c3ecf7b252a3 | 302 | //pc.printf("0.3"); |
Wayne Roberts |
0:c3ecf7b252a3 | 303 | if (FloraPreambleHi.bits.data_rate == 6) |
Wayne Roberts |
0:c3ecf7b252a3 | 304 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_3; |
Wayne Roberts |
0:c3ecf7b252a3 | 305 | if (FloraPreambleHi.bits.data_rate == 7) |
Wayne Roberts |
0:c3ecf7b252a3 | 306 | mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_125_BW_0_3; |
Wayne Roberts |
0:c3ecf7b252a3 | 307 | break; |
Wayne Roberts |
0:c3ecf7b252a3 | 308 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 309 | //pc.printf("MHz bw:%u\r\n", RegRxBw.bits.bw); |
Wayne Roberts |
0:c3ecf7b252a3 | 310 | mpBLE_GFSK.gfskBle.bitrateBandwidth = reg8; |
Wayne Roberts |
0:c3ecf7b252a3 | 311 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 312 | |
Wayne Roberts |
0:c3ecf7b252a3 | 313 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 314 | FskCfg_t FskCfg; |
Wayne Roberts |
0:c3ecf7b252a3 | 315 | FskCfg.octet = radio.readReg(REG_ADDR_FSK_CFG, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 316 | //pc.printf("gf_bt:%u\r\n", FskCfg.bits.gf_bt); |
Wayne Roberts |
0:c3ecf7b252a3 | 317 | mpBLE_GFSK.gfskBle.ModulationShaping = FskCfg.bits.gf_bt << 4; |
Wayne Roberts |
0:c3ecf7b252a3 | 318 | mpFLRC.flrc.ModulationShaping = mpBLE_GFSK.gfskBle.ModulationShaping; |
Wayne Roberts |
0:c3ecf7b252a3 | 319 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 320 | |
Wayne Roberts |
0:c3ecf7b252a3 | 321 | { |
Wayne Roberts |
0:c3ecf7b252a3 | 322 | PktBitStreamCtrl_t PktBitStreamCtrl; |
Wayne Roberts |
0:c3ecf7b252a3 | 323 | PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1); |
Wayne Roberts |
0:c3ecf7b252a3 | 324 | mpFLRC.flrc.CodingRate = PktBitStreamCtrl.octet & 0x06; // PktBitStreamCtrl.bits.flora_coding_rate |
Wayne Roberts |
0:c3ecf7b252a3 | 325 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 326 | #endif /* if 0 */ |
Wayne Roberts |
0:c3ecf7b252a3 | 327 | |
Wayne Roberts |
0:c3ecf7b252a3 | 328 | } |
Wayne Roberts |
0:c3ecf7b252a3 | 329 | |
Wayne Roberts |
0:c3ecf7b252a3 | 330 | #endif /* SX128x_H */ |