test sending sensor results over lora radio. Accelerometer and temp/pressure.
Serial terminal operates at 115200.
This project provides a text-based menu over serial port.
Operating the program only requires using the arrow keys, enter key to activate a control, or entering numbers.
Two sensors provided:
LIS12DH12
accelerometer operates in a continuous sampling mode. Enable control for accelerometer enables this continuous sampling, approx every 3 seconds.
LPS22HH temperature / pressure sensor operates as single shot, where pressing the control button on terminal causes single sample to be performed.
poll rate
control will enable repeated reading of pressure/temperature-sensor or photo-sensor when poll rate is greater than zero.
target must be: DISCO_L072CZ_LRWAN1
TARGET_DISCO_L072CZ_LRWAN1/radio_typeABZ.cpp@2:972a5704f152, 2019-04-29 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Mon Apr 29 13:54:35 2019 -0700
- Revision:
- 2:972a5704f152
- Parent:
- 0:e1e70da93044
add Ticker for polling photo-sensor and pressure/temp-sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:e1e70da93044 | 1 | #include "radio.h" |
Wayne Roberts |
0:e1e70da93044 | 2 | |
Wayne Roberts |
0:e1e70da93044 | 3 | SPI spi(PA_7, PA_6, PB_3); // mosi, miso, sclk |
Wayne Roberts |
0:e1e70da93044 | 4 | // dio0, dio1, nss, spi, rst |
Wayne Roberts |
0:e1e70da93044 | 5 | SX127x Radio::radio(PB_4, PB_1, PA_15, spi, PC_0); |
Wayne Roberts |
0:e1e70da93044 | 6 | SX127x_lora Radio::lora(radio); |
Wayne Roberts |
0:e1e70da93044 | 7 | SX127x_fsk Radio::fsk(radio); |
Wayne Roberts |
0:e1e70da93044 | 8 | |
Wayne Roberts |
0:e1e70da93044 | 9 | #define CRF1 PA_1 |
Wayne Roberts |
0:e1e70da93044 | 10 | #define CRF2 PC_2 |
Wayne Roberts |
0:e1e70da93044 | 11 | #define CRF3 PC_1 |
Wayne Roberts |
0:e1e70da93044 | 12 | DigitalOut Vctl1(CRF1); |
Wayne Roberts |
0:e1e70da93044 | 13 | DigitalOut Vctl2(CRF2); |
Wayne Roberts |
0:e1e70da93044 | 14 | DigitalOut Vctl3(CRF3); |
Wayne Roberts |
0:e1e70da93044 | 15 | |
Wayne Roberts |
0:e1e70da93044 | 16 | void Radio::rfsw_callback() |
Wayne Roberts |
0:e1e70da93044 | 17 | { |
Wayne Roberts |
0:e1e70da93044 | 18 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { |
Wayne Roberts |
0:e1e70da93044 | 19 | Vctl1 = 0; |
Wayne Roberts |
0:e1e70da93044 | 20 | if (radio.RegPaConfig.bits.PaSelect) { |
Wayne Roberts |
0:e1e70da93044 | 21 | Vctl2 = 0; |
Wayne Roberts |
0:e1e70da93044 | 22 | Vctl3 = 1; |
Wayne Roberts |
0:e1e70da93044 | 23 | } else { |
Wayne Roberts |
0:e1e70da93044 | 24 | Vctl2 = 1; |
Wayne Roberts |
0:e1e70da93044 | 25 | Vctl3 = 0; |
Wayne Roberts |
0:e1e70da93044 | 26 | } |
Wayne Roberts |
0:e1e70da93044 | 27 | } else { |
Wayne Roberts |
0:e1e70da93044 | 28 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE) |
Wayne Roberts |
0:e1e70da93044 | 29 | Vctl1 = 1; |
Wayne Roberts |
0:e1e70da93044 | 30 | else |
Wayne Roberts |
0:e1e70da93044 | 31 | Vctl1 = 0; |
Wayne Roberts |
0:e1e70da93044 | 32 | |
Wayne Roberts |
0:e1e70da93044 | 33 | Vctl2 = 0; |
Wayne Roberts |
0:e1e70da93044 | 34 | Vctl3 = 0; |
Wayne Roberts |
0:e1e70da93044 | 35 | } |
Wayne Roberts |
0:e1e70da93044 | 36 | } |
Wayne Roberts |
0:e1e70da93044 | 37 | |
Wayne Roberts |
0:e1e70da93044 | 38 | void Radio::tx_dbm_print() |
Wayne Roberts |
0:e1e70da93044 | 39 | { |
Wayne Roberts |
0:e1e70da93044 | 40 | int dbm; |
Wayne Roberts |
0:e1e70da93044 | 41 | RegPdsTrim1_t pds_trim; |
Wayne Roberts |
0:e1e70da93044 | 42 | uint8_t adr, pa_test_adr; |
Wayne Roberts |
0:e1e70da93044 | 43 | |
Wayne Roberts |
0:e1e70da93044 | 44 | if (radio.type == SX1276) { |
Wayne Roberts |
0:e1e70da93044 | 45 | adr = REG_PDSTRIM1_SX1276; |
Wayne Roberts |
0:e1e70da93044 | 46 | pa_test_adr = REG_PATEST_SX1276; |
Wayne Roberts |
0:e1e70da93044 | 47 | } else { |
Wayne Roberts |
0:e1e70da93044 | 48 | adr = REG_PDSTRIM1_SX1272; |
Wayne Roberts |
0:e1e70da93044 | 49 | pa_test_adr = REG_PATEST_SX1272; |
Wayne Roberts |
0:e1e70da93044 | 50 | } |
Wayne Roberts |
0:e1e70da93044 | 51 | |
Wayne Roberts |
0:e1e70da93044 | 52 | if (radio.read_reg(pa_test_adr) & 0x20) { |
Wayne Roberts |
0:e1e70da93044 | 53 | pds_trim.octet = radio.read_reg(adr); |
Wayne Roberts |
0:e1e70da93044 | 54 | |
Wayne Roberts |
0:e1e70da93044 | 55 | radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG); |
Wayne Roberts |
0:e1e70da93044 | 56 | if (radio.RegPaConfig.bits.PaSelect) { |
Wayne Roberts |
0:e1e70da93044 | 57 | dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2; |
Wayne Roberts |
0:e1e70da93044 | 58 | } else { |
Wayne Roberts |
0:e1e70da93044 | 59 | dbm = radio.RegPaConfig.bits.OutputPower - 1; |
Wayne Roberts |
0:e1e70da93044 | 60 | } |
Wayne Roberts |
0:e1e70da93044 | 61 | } else |
Wayne Roberts |
0:e1e70da93044 | 62 | dbm = PA_OFF_DBM; |
Wayne Roberts |
0:e1e70da93044 | 63 | |
Wayne Roberts |
0:e1e70da93044 | 64 | pc.printf("%d", dbm); |
Wayne Roberts |
0:e1e70da93044 | 65 | } |
Wayne Roberts |
0:e1e70da93044 | 66 | |
Wayne Roberts |
0:e1e70da93044 | 67 | bool Radio::tx_dbm_write(const char* str) |
Wayne Roberts |
0:e1e70da93044 | 68 | { |
Wayne Roberts |
0:e1e70da93044 | 69 | int dbm; |
Wayne Roberts |
0:e1e70da93044 | 70 | uint8_t adr; |
Wayne Roberts |
0:e1e70da93044 | 71 | RegPdsTrim1_t pds_trim; |
Wayne Roberts |
0:e1e70da93044 | 72 | |
Wayne Roberts |
0:e1e70da93044 | 73 | sscanf(str, "%d", &dbm); |
Wayne Roberts |
0:e1e70da93044 | 74 | |
Wayne Roberts |
0:e1e70da93044 | 75 | if (radio.type == SX1276) |
Wayne Roberts |
0:e1e70da93044 | 76 | adr = REG_PDSTRIM1_SX1276; |
Wayne Roberts |
0:e1e70da93044 | 77 | else |
Wayne Roberts |
0:e1e70da93044 | 78 | adr = REG_PDSTRIM1_SX1272; |
Wayne Roberts |
0:e1e70da93044 | 79 | |
Wayne Roberts |
0:e1e70da93044 | 80 | pds_trim.octet = radio.read_reg(adr); |
Wayne Roberts |
0:e1e70da93044 | 81 | |
Wayne Roberts |
0:e1e70da93044 | 82 | if (dbm > 14) { |
Wayne Roberts |
0:e1e70da93044 | 83 | radio.RegPaConfig.bits.PaSelect = 1; // PA_BOOST |
Wayne Roberts |
0:e1e70da93044 | 84 | if (dbm > 17) { |
Wayne Roberts |
0:e1e70da93044 | 85 | dbm -= 3; |
Wayne Roberts |
0:e1e70da93044 | 86 | pds_trim.bits.prog_txdac = 7; |
Wayne Roberts |
0:e1e70da93044 | 87 | radio.write_reg(adr, pds_trim.octet); |
Wayne Roberts |
0:e1e70da93044 | 88 | } |
Wayne Roberts |
0:e1e70da93044 | 89 | radio.RegPaConfig.bits.OutputPower = dbm - 2; |
Wayne Roberts |
0:e1e70da93044 | 90 | } else { |
Wayne Roberts |
0:e1e70da93044 | 91 | radio.RegPaConfig.bits.PaSelect = 0; // RFO |
Wayne Roberts |
0:e1e70da93044 | 92 | radio.RegPaConfig.bits.OutputPower = dbm + 1; |
Wayne Roberts |
0:e1e70da93044 | 93 | } |
Wayne Roberts |
0:e1e70da93044 | 94 | |
Wayne Roberts |
0:e1e70da93044 | 95 | radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet); |
Wayne Roberts |
0:e1e70da93044 | 96 | |
Wayne Roberts |
0:e1e70da93044 | 97 | return false; |
Wayne Roberts |
0:e1e70da93044 | 98 | } |
Wayne Roberts |
0:e1e70da93044 | 99 | |
Wayne Roberts |
0:e1e70da93044 | 100 | void Radio::targetInit() |
Wayne Roberts |
0:e1e70da93044 | 101 | { |
Wayne Roberts |
0:e1e70da93044 | 102 | radio.rf_switch = rfsw_callback; |
Wayne Roberts |
0:e1e70da93044 | 103 | } |