Text menu driven ANSI/VT100 console test utility for LoRa transceivers
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.
This is VT100 text-based menu driven test program for SX12xx transceiver devices.
Serial console is divided into horizontally into top half and bottom half.
The bottom half serves as scrolling area to log activity.
The top half serves as menu, to configure the radio.
For all devices, the serial console operates at 115200 8N1, and requires terminal with ANSI-VT100 capability, such as putty/teraterm/minicom etc.
Use program only with keyboard up/down/left/right keys. Enter to change an item, or number for value item. Some items are single bit, requiring only enter key to toggle. Others with fixed choices give a drop-down menu.
TARGET_MOTE_L152RC/radio_mote.cpp
- Committer:
- Wayne Roberts
- Date:
- 2018-08-20
- Revision:
- 1:0817a150122b
- Child:
- 5:1e5cb7139acb
File content as of revision 1:0817a150122b:
#include "radio.h" #define RADIO_RESET PC_2 //NorAm_Mote Reset_sx #define RADIO_MOSI PB_15 //NorAm_Mote SPI2 Mosi #define RADIO_MISO PB_14 //NorAm_Mote SPI2 Miso #define RADIO_SCLK PB_13 //NorAm_Mote SPI2 Clk #define RADIO_NSS PB_12 //NorAm_Mote SPI2 Nss #define RADIO_DIO_0 PC_6 //NorAm_Mote DIO0 #define RADIO_DIO_1 PC_10 //NorAm_Mote DIO1 #define RADIO_DIO_2 PC_8 //NorAm_Mote DIO2 #define RADIO_DIO_3 PB_4 //NorAm_Mote DIO3 #define RADIO_DIO_4 PB_5 //NorAm_Mote DIO4 #define RADIO_DIO_5 PB_6 //NorAm_Mote DIO5 #define RFSW1 PC_4 //NorAm_Mote RFSwitch_CNTR_1 #define RFSW2 PC_13 //NorAm_Mote RFSwitch_CNTR_2 SPI spi(RADIO_MOSI, RADIO_MISO, RADIO_SCLK); // mosi, miso, sclk // dio0, dio1, nss, spi, rst SX127x Radio::radio(RADIO_DIO_0, RADIO_DIO_1, RADIO_NSS, spi, RADIO_RESET); SX127x_lora Radio::lora(radio); SX127x_fsk Radio::fsk(radio); DigitalOut rfsw1(RFSW1); DigitalOut rfsw2(RFSW2); DigitalOut red(LED1); DigitalOut yellow(LED3); #define LED_OFF 1 #define LED_ON 0 void Radio::rfsw_callback() { if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { // start of transmission red = LED_ON; yellow = LED_OFF; if (radio.HF) { if (radio.RegPaConfig.bits.PaSelect) { // if PA_BOOST rfsw2 = 0; rfsw1 = 1; } else { // RFO to power amp rfsw2 = 1; rfsw1 = 0; } } else { // todo: sx1276 } } else if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE || radio.RegOpMode.bits.Mode == RF_OPMODE_CAD) { // start of reception red = LED_OFF; yellow = LED_ON; if (radio.HF) { rfsw2 = 1; rfsw1 = 1; } else { // todo: sx1276 } } else { // RF switch shutdown yellow = LED_OFF; red = LED_OFF; rfsw2 = 0; rfsw1 = 0; } } void Radio::tx_dbm_print() { int dbm; radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG); if (radio.RegPaConfig.bits.PaSelect) { RegPdsTrim1_t pds_trim; uint8_t adr; if (radio.type == SX1276) adr = REG_PDSTRIM1_SX1276; else adr = REG_PDSTRIM1_SX1272; pds_trim.octet = radio.read_reg(adr); dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2; } else { dbm = radio.RegPaConfig.bits.OutputPower - 21; } pc.printf(":%d", dbm); } bool Radio::tx_dbm_write(const char* str) { int dbm; sscanf(str, "%d", &dbm); if (dbm > 20) { radio.RegPaConfig.bits.PaSelect = 0; // RFO to external amplifier dbm -= 20; if (dbm < 15) radio.RegPaConfig.bits.OutputPower = dbm + 1; } else { uint8_t adr; RegPdsTrim1_t pds_trim; radio.RegPaConfig.bits.PaSelect = 1; // PA_BOOST /* PABOOST used: +2dbm to +17, or +20 */ if (radio.type == SX1276) adr = REG_PDSTRIM1_SX1276; else adr = REG_PDSTRIM1_SX1272; pds_trim.octet = radio.read_reg(adr); if (dbm > 17) { dbm -= 3; pds_trim.bits.prog_txdac = 7; radio.write_reg(adr, pds_trim.octet); } if (dbm > 1) radio.RegPaConfig.bits.OutputPower = dbm - 2; } radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet); return false; } void Radio::targetInit() { radio.rf_switch = rfsw_callback; }