point-2-point demo

Dependencies:   sx12xx_hal

radio chip selection

Radio chip driver is not included, because these options are available.
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.

TX trigger selection

Edit main.h to define DIGITAL_TRIGGER or ANALOG_TRIGGER to chose whether transmit is initiated by digital pin (button/jumper) or analog pin(s) level change.

This project is intended to be used on two LoRa shields.

Each board sits in continuous RX mode, waiting for request packet.
If the received packet has good CRC, the packet is acknowledged along with read of ADC sample from the replying device.
The original request packet also contains instruction to set level of output pin.

Both sides of the link are running the same code, and each can initiate a transmission at any time.
No addressing is used, so only two nodes can operate on the radio channel.

Committer:
Wayne Roberts
Date:
Wed Aug 01 15:04:11 2018 -0700
Revision:
5:e35b1b281466
move analog to separate source file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 5:e35b1b281466 1 #include "main.h"
Wayne Roberts 5:e35b1b281466 2 #ifdef DIGITAL_TRIGGER
Wayne Roberts 5:e35b1b281466 3
Wayne Roberts 5:e35b1b281466 4 Ticker ticker;
Wayne Roberts 5:e35b1b281466 5 InterruptIn user_button(USER_BUTTON);
Wayne Roberts 5:e35b1b281466 6
Wayne Roberts 5:e35b1b281466 7 DigitalOut jumper_out(PC_10);
Wayne Roberts 5:e35b1b281466 8 InterruptIn jumper_in(PC_12);
Wayne Roberts 5:e35b1b281466 9 volatile bool start_tx;
Wayne Roberts 5:e35b1b281466 10
Wayne Roberts 5:e35b1b281466 11 volatile bool jin;
Wayne Roberts 5:e35b1b281466 12 uint8_t out_pin_state;
Wayne Roberts 5:e35b1b281466 13
Wayne Roberts 5:e35b1b281466 14 void button_isr()
Wayne Roberts 5:e35b1b281466 15 {
Wayne Roberts 5:e35b1b281466 16 if (!jumper_in.read())
Wayne Roberts 5:e35b1b281466 17 start_tx = true;
Wayne Roberts 5:e35b1b281466 18 }
Wayne Roberts 5:e35b1b281466 19
Wayne Roberts 5:e35b1b281466 20 void auto_tx()
Wayne Roberts 5:e35b1b281466 21 {
Wayne Roberts 5:e35b1b281466 22 if (jumper_in.read())
Wayne Roberts 5:e35b1b281466 23 start_tx = true;
Wayne Roberts 5:e35b1b281466 24 else
Wayne Roberts 5:e35b1b281466 25 ticker.detach();
Wayne Roberts 5:e35b1b281466 26 }
Wayne Roberts 5:e35b1b281466 27
Wayne Roberts 5:e35b1b281466 28 void trigger_init()
Wayne Roberts 5:e35b1b281466 29 {
Wayne Roberts 5:e35b1b281466 30 jin = false;
Wayne Roberts 5:e35b1b281466 31
Wayne Roberts 5:e35b1b281466 32 jumper_out = 1;
Wayne Roberts 5:e35b1b281466 33 jumper_in.mode(PullDown);
Wayne Roberts 5:e35b1b281466 34
Wayne Roberts 5:e35b1b281466 35 while (!user_button) {
Wayne Roberts 5:e35b1b281466 36 printf("button-lo\r\n");
Wayne Roberts 5:e35b1b281466 37 wait(0.01);
Wayne Roberts 5:e35b1b281466 38 }
Wayne Roberts 5:e35b1b281466 39 user_button.fall(&button_isr);
Wayne Roberts 5:e35b1b281466 40 }
Wayne Roberts 5:e35b1b281466 41
Wayne Roberts 5:e35b1b281466 42 void trigger_mainloop()
Wayne Roberts 5:e35b1b281466 43 {
Wayne Roberts 5:e35b1b281466 44 if (jumper_in.read()) {
Wayne Roberts 5:e35b1b281466 45 if (!jin) {
Wayne Roberts 5:e35b1b281466 46 ticker.attach(auto_tx, 0.5);
Wayne Roberts 5:e35b1b281466 47 jin = true;
Wayne Roberts 5:e35b1b281466 48 }
Wayne Roberts 5:e35b1b281466 49 } else {
Wayne Roberts 5:e35b1b281466 50 jin = false;
Wayne Roberts 5:e35b1b281466 51 }
Wayne Roberts 5:e35b1b281466 52
Wayne Roberts 5:e35b1b281466 53 if (start_tx) {
Wayne Roberts 5:e35b1b281466 54 start_tx = false;
Wayne Roberts 5:e35b1b281466 55
Wayne Roberts 5:e35b1b281466 56 uint8_t buf[2];
Wayne Roberts 5:e35b1b281466 57 out_pin_state ^= 1;
Wayne Roberts 5:e35b1b281466 58 buf[0] = CMD_OUT_PIN;
Wayne Roberts 5:e35b1b281466 59 buf[1] = out_pin_state;
Wayne Roberts 5:e35b1b281466 60 radio_tx(buf, 2);
Wayne Roberts 5:e35b1b281466 61 }
Wayne Roberts 5:e35b1b281466 62 }
Wayne Roberts 5:e35b1b281466 63
Wayne Roberts 5:e35b1b281466 64 #endif /* DIGITAL_TRIGGER */
Wayne Roberts 5:e35b1b281466 65