UART console application for testing SX1272/SX1276

Dependencies:   SX127x

/media/uploads/dudmuck/lora.png

This is a UART console test application for using SX127x library driver for SX1272/SX1276 radio transceivers. Serial console is provided at 57600bps. Refer to Serial Communication with a PC for information about using the serial port with your PC.

Using this command interface, you can exercise the functionality of radio chip without needing specialized software application for your PC.

Commands which can be used include ? to list available commands, or . to query status from radio chip, for example. The serial console allows you to configure the radio chip, such as setting spreading factor, bandwidth, operating frequency, etc.

A simple chat application is provided to try communications between two boards. The SX127x library object is instantiated with pin assignments generic arduino headers, but can be easily reassigned for any mbed board.

The same driver library can operate for both SX1272 and SX1276. Upon starting, the driver auto-detects whether SX1272 or SX1276 transceiver chip is connected by attempting to change the LowFrequencyModeOn bit in RegOpMode register. If this bit can be changed, then the radio device is SX1276. This bit is not implemented in SX1272. A few of the radio driver functions select behavior based on this detection. The differences between these two devices is small, from a software perspective.

Using with SX1276MB1xAS Shield

This component plugs into any board with arduino uno headers.

There are two different version of this shield. European version (MAS), and North American (LAS). The LAS shield uses PA_BOOST transmit pin to permit +20dBm power. The MAS version uses RFO transmit pin in Europe. This software reads RF switch pin (A4 pin) pulling resistor to determine which type of shield is installed.


Using with your own production board

This software is useful for validating RF performance your own LoRa board design, because only two external pins needs to be provided to PC (UART TX/RX). You can select an mbed platform which matches the CPU on your own board. If the memory size doesnt match exactly, you can export the program to an offline toolchain and edit the target type or linker file there.

Transmitter Test Guidelines

FSK mode is used for transmitter testing, because an unmodulated carrier can be sent, permitting easy measurement of TX power and frequency error.

commands used for transmitter testing:

  • frf915.0 change to your desired RF center frequency (in this case 915MHz)
  • L to toggle the radio chip into FSK mode.
  • fdev0 to configure TX frequency deviation to zero, to put the transmitted carrier on the center frequency.
  • pas to select which TX pin is connected to antenna matching (RFO vs PA_BOOST).
  • op<dBm> to configure TX power.
  • If you desire to test higher power PA_BOOST, use ocp<mA>
  • w 01 03 put radio chip into transmit mode (skips writing to FIFO). This will cause radio to transmit preamble, because the FIFO is empty in TX mode. Since Fdev is zero, an unmodulated carrier is sent.
  • Spectrum analyzer can now be used to to observe TX power, harmonics, power consumption, or frequency error.
  • stby to end transmission, or use h to reset radio chip to default condition.
  • Use period . command at any time to review current radio configuration.

LoRa transmitter testing

  • use L command to toggle radio into LoRa, if necessary.
  • Normally the tx command is used to manually send single packets.
  • txc will toggle TxContinuousMode in LoRa modem to send continuous modulated transmission.
  • Useful for checking adjacent channel power.
  • enter txc again to end transmission.

Receiver Test Guidelines

FSK mode is used for receiver sensitivity testing, allowing the use of a BERT signal generator (such as R/S SMIQ03B). Using this method provides real-time indication of receiver sensitivity, useful for tuning and impedance matching. The radio chip outputs DCLK and DATA digital signals which are connected back to BERT signal generator.

commands used for receiver testing:

  • L to toggle the radio chip into FSK mode.
  • datam to toggle FSK modem into continuous mode. This disables packet engine and gives direct access to demodulator.
  • configure DIO1 pin to DCLK function, and DIO2 pin to DATA function:
    • dio command to list current DIO pin asignments
    • d1 to cycle DIO1 function until Dclk is selected
    • d2 for DIO2, only Data function is available in FSK continuous mode
  • frf915.0 change to your desired RF center frequency (in this case 915MHz)
  • rx to start receiver
  • stby to disable receiver

Full command list

Arguments shown in square brackets [] indicate required. <> are optional, where leaving off the argument usually causes a read of the item, and providing the value causes a write operation. You should always have the radio chip datasheet on-hand when using these commands.

Hitting <enter> key by itself will repeat last command.
<Ctrl-C> will cancel an operation in progress.

command list: common commands (both LoRa and FSK)

commanddescription
. (period)print current radio status
?list available commands
Ltoggle active radio modem (LoRa vs FSK)
hhardware reset, put radio into default power-on condition
frf<MHz>get/set RF operating frequency
rxstart radio receiver (any received packets are printed onto your serial terminal)
rssiread instantaneous RSSI (level read at the time command is issued)
tx<%d>transmit test packet. Packet length value can be provided as argument, or uses last value if not provided
payl<%d>get/set payload length
bw<KHz>get/set bandwidth. In LoRa mode, both receive and transmit bandwidth are changed. For FSK, only receive bandwidth is affected. bwa accesses AFC bandwidth in FSK
pastoggle RFO / PA_BOOST transmit pin output selection
op<dBm>get/set TX output power. Value is provided in dBm. Special case is value of 20dBm (on PA_BOOST), which causes increase in TX DAC voltage
ocp<mA>get/set TX current limit, in milliamps. Necessary adjustment when +20dBm is used
dioshow DIO pin assignments
d<0-5>change DIO pin assignment, the pin number is given as arguement. Each pin has up to 4 possible functions
pres<%d>set preamble length. LoRa: number of symbols. FSK: number of bytes
crcontoggle crcOn
lnabcycle LNA-boost setting (receiver performance adjustment)
Rread all radio registers (use only while reading chip datasheet)
r[%x]read single radio register (use only while reading chip datasheet)
w[%x %x]write single radio register (use only while reading chip datasheet)
pllbwchange PLL bandwidth
stbyset chip mode to standby
sleepset chip mode to sleep
fstxset chip mode to fstx
fsrxset chip mode to fsrx
Eiger range test commandsdescription
pid<%d>get set ID number in range test payload
pertx<%d>start Eiger PER transmit. The count of packets to send is provided as arguement
perrxstart Eiger PER receive
txpd<%d>get/set tx delay between PER packets transmitted

command list: LoRa modem commands

LoRa commandLoRa description
iqinvtoggle RX IQ invert
cintoggle TX IQ invert
lhp<%d>(RX) get/set hop period
sync<%x>get/set sync (post-preamble gap, single byte)
cr<1-4>get/set codingRate
lhmtoggle explicit/implicit (explicit mode sends payload length with each packet)
sf<%d>get/set spreadingFactor (SF7 to SF12)
ldrtoggle LowDataRateOptimize (changes payload encoding, for long packets)
txctoggle TxContinuousMode
rxt<%d>get/set SymbTimeout
rxsstart RX_SINGLE (receives only for SymbTimeout symbols)
cad<%d num tries>run channel activity detection

command list: FSK modem commands

FSK commandFSK description
c<%d>get/set test cases. Several FSK bitrates/bandwidths pre-configured to give optimal performance.
fdev<kHz>(TX) get/set frequency deviation
mods(TX) increment modulation shaping
par(TX) increment paRamp
datamtoggle DataMode (packet/continuous)
fifottoggle TxStartCondition (FifoThreshold level vs FifoNotEmpty)
br<%f kbps>get/set bitrate
dcfincrement DcFree (manchester / whitening)
pktftoggle PacketFormat fixed/variable length
syncontoggle SyncOn (frame sync, SFD enable)
bitsynctoggle BitSyncOn (continuous mode only)
syncw<hex bytes>get/set syncword. Sync bytes are provided by hex octects separated by spaces.
fei(RX) read FEI
rxt(RX) increment RxTrigger (RX start on rssi vs. preamble detect)
rssit<-dBm>(RX) get/set rssi threshold (trigger level for RSSI interrupt)
rssis<%d>(RX) get/set rssi smoothing
rssio<%d>(RX) get/set rssi offset
agcauto(RX) toggle AgcAutoOn (true = LNA gain set automatically)
afcauto(RX) toggle AfcAutoOn
ac(RX) AfcClear
ar(RX) increment AutoRestartRxMode
alc(RX) toggle AfcAutoClearOn (only if AfcAutoOn is set)
prep(RX) toggle PreamblePolarity (0xAA vs 0x55)
pde(RX) toggle PreambleDetectorOn
pds<%d>(RX) get/set PreambleDetectorSize
pdt<%d>(RX) get/set PreambleDetectorTol
mp(RX) toggle MapPreambleDetect (DIO function RSSI vs PreambleDetect)
thr<%d>get/set FifoThreshold (triggers FifoLevel interrupt)
polltoggle poll_irq_en. Radio events read from DIO pins vs polling of IrqFlags register
Eempty out FIFO
clkoutincrement ClkOut divider
ookenter OOK mode
ooktincrement OokThreshType
ooksincrement OokPeakTheshStep
sqlch<%d>get/set OokFixedThresh
Committer:
Wayne Roberts
Date:
Tue May 22 15:55:15 2018 -0700
Revision:
24:9ba45aa15b53
Parent:
18:9530d682fd9a
remove TYPE_ABZ: use discovery-l073rz target.   updated to latest sx127x library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dudmuck 18:9530d682fd9a 1 #if 0
dudmuck 18:9530d682fd9a 2 #include "mbed.h"
dudmuck 18:9530d682fd9a 3
dudmuck 18:9530d682fd9a 4 #define RADIO_FILE_XFER
dudmuck 18:9530d682fd9a 5
dudmuck 18:9530d682fd9a 6 #ifdef RADIO_FILE_XFER
dudmuck 18:9530d682fd9a 7 #include "sx127x_lora.h"
dudmuck 18:9530d682fd9a 8 #endif /* RADIO_FILE_XFER */
dudmuck 18:9530d682fd9a 9
dudmuck 18:9530d682fd9a 10
dudmuck 18:9530d682fd9a 11 #define SOH 0x01
dudmuck 18:9530d682fd9a 12 #define NAK 0x15
dudmuck 18:9530d682fd9a 13 #define CAN 0x18
dudmuck 18:9530d682fd9a 14
dudmuck 18:9530d682fd9a 15 typedef enum {
dudmuck 18:9530d682fd9a 16 KERMIT_STATE_OFF = 0,
dudmuck 18:9530d682fd9a 17 KERMIT_STATE_WAIT_SOH,
dudmuck 18:9530d682fd9a 18 KERMIT_STATE_WAIT_LEN,
dudmuck 18:9530d682fd9a 19 KERMIT_STATE_WAIT_SEQ,
dudmuck 18:9530d682fd9a 20 KERMIT_STATE_WAIT_TYPE,
dudmuck 18:9530d682fd9a 21 KERMIT_STATE_DATA,
dudmuck 18:9530d682fd9a 22 KERMIT_STATE_GET_EOL,
dudmuck 18:9530d682fd9a 23 } kermit_state_e;
dudmuck 18:9530d682fd9a 24
dudmuck 18:9530d682fd9a 25
dudmuck 18:9530d682fd9a 26 class Kermit
dudmuck 18:9530d682fd9a 27 {
dudmuck 18:9530d682fd9a 28 public:
dudmuck 18:9530d682fd9a 29 Kermit(SX127x_lora& _lora);
dudmuck 18:9530d682fd9a 30 ~Kermit();
dudmuck 18:9530d682fd9a 31
dudmuck 18:9530d682fd9a 32 bool uart_rx_enabled;
dudmuck 18:9530d682fd9a 33 bool got_send_init;
dudmuck 18:9530d682fd9a 34 bool end;
dudmuck 18:9530d682fd9a 35 uint8_t end_cause;
dudmuck 18:9530d682fd9a 36 uint32_t total_file_bytes;
dudmuck 18:9530d682fd9a 37 SX127x_lora& lora;
dudmuck 18:9530d682fd9a 38 char filename[128];
dudmuck 18:9530d682fd9a 39
dudmuck 18:9530d682fd9a 40 uint32_t bin_data_u32[128];
dudmuck 18:9530d682fd9a 41 uint8_t* bin_data;
dudmuck 18:9530d682fd9a 42 uint32_t bin_data_idx;
dudmuck 18:9530d682fd9a 43
dudmuck 18:9530d682fd9a 44 uint8_t maxl;
dudmuck 18:9530d682fd9a 45 uint8_t time;
dudmuck 18:9530d682fd9a 46 uint8_t npad;
dudmuck 18:9530d682fd9a 47 char padc;
dudmuck 18:9530d682fd9a 48 char eol;
dudmuck 18:9530d682fd9a 49 char qctl; // verbatim quote char
dudmuck 18:9530d682fd9a 50 char qbin;
dudmuck 18:9530d682fd9a 51 char chkt;
dudmuck 18:9530d682fd9a 52 char rept;
dudmuck 18:9530d682fd9a 53
dudmuck 18:9530d682fd9a 54 void rx_callback(uint8_t);
dudmuck 18:9530d682fd9a 55 void uart_rx_enable(void);
dudmuck 18:9530d682fd9a 56 void service(void);
dudmuck 18:9530d682fd9a 57 uint32_t _HAL_CRC_Calculate(uint32_t u32_buf[], uint32_t Size);
dudmuck 18:9530d682fd9a 58 void test_crc(void);
dudmuck 18:9530d682fd9a 59
dudmuck 18:9530d682fd9a 60 protected:
dudmuck 18:9530d682fd9a 61 bool show_error;
dudmuck 18:9530d682fd9a 62 bool end_after_tx;
dudmuck 18:9530d682fd9a 63 kermit_state_e state;
dudmuck 18:9530d682fd9a 64 void kermit_uart_tx(void);
dudmuck 18:9530d682fd9a 65 int parse_rx(void);
dudmuck 18:9530d682fd9a 66 void radio_xfer_rx(void);
dudmuck 18:9530d682fd9a 67
dudmuck 18:9530d682fd9a 68 uint8_t tochar(uint8_t c);
dudmuck 18:9530d682fd9a 69 uint8_t unchar(uint8_t c);
dudmuck 18:9530d682fd9a 70 uint8_t ctl(uint8_t c);
dudmuck 18:9530d682fd9a 71
dudmuck 18:9530d682fd9a 72 uint32_t uart_rx_sum;
dudmuck 18:9530d682fd9a 73 uint8_t uart_rx_data[128];
dudmuck 18:9530d682fd9a 74 uint8_t uart_rx_data_idx;
dudmuck 18:9530d682fd9a 75 uint8_t uart_rx_length;
dudmuck 18:9530d682fd9a 76 char uart_rx_seq;
dudmuck 18:9530d682fd9a 77 char uart_rx_type;
dudmuck 18:9530d682fd9a 78
dudmuck 18:9530d682fd9a 79 float uart_tx_sleep;
dudmuck 18:9530d682fd9a 80 uint8_t uart_tx_data[128];
dudmuck 18:9530d682fd9a 81 uint8_t uart_tx_data_idx;
dudmuck 18:9530d682fd9a 82 bool uart_do_tx;
dudmuck 18:9530d682fd9a 83 };
dudmuck 18:9530d682fd9a 84 #endif /* #if 0 */