point-2-point demo
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.
Diff: main.cpp
- Revision:
- 1:d95d135a4fb4
- Parent:
- 0:1d8d218c5cc5
- Child:
- 2:5131512b4eb9
--- a/main.cpp Thu Oct 05 16:11:31 2017 -0700 +++ b/main.cpp Mon Oct 16 11:20:25 2017 -0700 @@ -1,4 +1,5 @@ #include "sx127x_lora.h" +#include "uart_cmds.h" DigitalOut myled(LED1); @@ -27,8 +28,6 @@ } /**********************************************************************/ -#define CMD_OUT_PIN 0x01 -#define CMD_OUT_PIN_ACK (CMD_OUT_PIN | 0x80) uint8_t out_pin_state; @@ -90,24 +89,29 @@ printf("tx-ack-end\r\n"); } -void tx() +void radio_tx(uint8_t* payload, uint8_t payload_len) { int i; + uint8_t n = 0; + uint16_t crc; + + while (payload_len > 0) { + //printf("n%u, paylen%u\r\n", n, payload_len); + payload_len--; + radio.tx_buf[payload_len] = payload[payload_len]; + n++; + } + + crc = crc16(radio.tx_buf, n); + radio.tx_buf[n++] = crc; + radio.tx_buf[n++] = crc >> 8; + + lora.RegPayloadLength = n; + radio.write_reg(REG_LR_PAYLOADLENGTH, lora.RegPayloadLength); for (i = 0; i < 3; i++) { - uint8_t n = 0; - uint16_t crc; int rx_timeout_at; - radio.tx_buf[n++] = CMD_OUT_PIN; - radio.tx_buf[n++] = out_pin_state; - crc = crc16(radio.tx_buf, n); - radio.tx_buf[n++] = crc; - radio.tx_buf[n++] = crc >> 8; - - lora.RegPayloadLength = n; - radio.write_reg(REG_LR_PAYLOADLENGTH, lora.RegPayloadLength); - lora.start_tx(lora.RegPayloadLength); /* begin transmission */ while (lora.service() != SERVICE_TX_DONE) /* wait for transmission to complete */ @@ -157,7 +161,7 @@ int main() { bool jin = false; - printf("\r\nreset\r\n"); + printf("\r\n2reset\r\n"); jumper_out = 1; jumper_in.mode(PullDown); @@ -209,9 +213,14 @@ } if (start_tx) { + start_tx = false; + + uint8_t buf[2]; out_pin_state ^= 1; - tx(); - start_tx = false; + buf[0] = CMD_OUT_PIN; + buf[1] = out_pin_state; + printf("start_tx...\r\n"); + radio_tx(buf, 2); } if (lora.service() == SERVICE_READ_FIFO) { uint16_t crc, rx_crc; @@ -225,7 +234,7 @@ crc = crc16(radio.rx_buf, lora.RegRxNbBytes-2); if (crc == rx_crc) { printf("crcOk\r\n"); - if (radio.rx_buf[0] == CMD_OUT_PIN) { + if (!parse_radio_rx(radio.rx_buf) && radio.rx_buf[0] == CMD_OUT_PIN) { pc6_out.write(radio.rx_buf[1]); printf("out pin state: %u", radio.rx_buf[1]); } @@ -234,6 +243,8 @@ } else printf("crc %04x != %04x\r\n", crc, rx_crc); } // ..if something received + + uart_service(); } // ..for (;;) }