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: uart_cmds.cpp
- Revision:
- 5:e35b1b281466
- Parent:
- 1:d95d135a4fb4
--- a/uart_cmds.cpp Tue Jul 17 14:32:29 2018 -0700 +++ b/uart_cmds.cpp Wed Aug 01 15:04:11 2018 -0700 @@ -1,7 +1,10 @@ #include <mbed.h> -#include "uart_cmds.h" +#include "main.h" -PwmOut pwm(PB_11); +PwmOut pwmA(PB_11); /* CN10-18 */ +PwmOut pwmB(PA_15); /* CN7-17 */ +PwmOut pwmC(PB_1); /* CN10-24 */ +PwmOut pwmD(PC_6); /* CN10-4 */ RawSerial pc(USBTX, USBRX); char pcbuf[128]; @@ -12,27 +15,38 @@ /* return true for parsed */ bool parse_radio_rx(uint8_t* rx_buf) { - if (rx_buf[0] == CMD_PWM) { - pwm.period(1.0 / rx_buf[1]); // rx_buf[1] is Hz - pwm.write(rx_buf[2] / 255.0); - printf("%uHz, duty:%.2f\r\n", rx_buf[1], rx_buf[2]/255.0); - return true; + PwmOut* pwmPtr; + + switch (rx_buf[0]) { + case CMD_PWM_A: pwmPtr = &pwmA; break; + case CMD_PWM_B: pwmPtr = &pwmB; break; + case CMD_PWM_C: pwmPtr = &pwmC; break; + case CMD_PWM_D: pwmPtr = &pwmD; break; + default: return false; } - return false; + pwmPtr->period(1.0 / rx_buf[1]); // rx_buf[1] is Hz + pwmPtr->write(rx_buf[2] / 255.0); + printf("%uHz, duty:%.2f\r\n", rx_buf[1], rx_buf[2]/255.0); + return true; } void cmd_pwm(uint8_t idx) { uint8_t buf[4]; - unsigned p, d; + unsigned ch, p, d; - if (sscanf(pcbuf+idx, "%u %u", &p, &d) != 2) { + if (sscanf(pcbuf+idx, "%u %u %u", &ch, &p, &d) != 3) { printf("parse fail\r\n"); return; } - buf[0] = CMD_PWM; + switch (ch) { + case 0: buf[0] = CMD_PWM_A; break; + case 1: buf[0] = CMD_PWM_B; break; + case 2: buf[0] = CMD_PWM_C; break; + case 3: buf[0] = CMD_PWM_D; break; + } buf[1] = p; buf[2] = d; radio_tx(buf, 3);