Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: sx126x sx12xx_hal
Diff: main.cpp
- Revision:
- 2:bf201940a9db
- Parent:
- 1:6a3a48d657a9
- Child:
- 3:f81d64ff0164
diff -r 6a3a48d657a9 -r bf201940a9db main.cpp
--- a/main.cpp Thu Aug 31 23:14:55 2017 +0000
+++ b/main.cpp Fri Jan 26 01:19:39 2018 +0000
@@ -1,35 +1,78 @@
#include "sx127x_lora.h"
DigitalOut myled(LED1);
-
-SPI spi(D11, D12, D13); // mosi, miso, sclk
-// dio0, dio1, nss, spi, rst
-SX127x radio( D2, D3, D10, spi, A0); // sx1276 arduino shield
-
+#ifdef TARGET_DISCO_L072CZ_LRWAN1
+
+ SPI spi(PA_7, PA_6, PB_3); // mosi, miso, sclk
+ // dio0, dio1, nss, spi, rst
+ SX127x radio(PB_4, PB_1, PA_15, spi, PC_0);
+
+ #define CRF1 PA_1
+ #define CRF2 PC_2
+ #define CRF3 PC_1
+ DigitalOut Vctl1(CRF1);
+ DigitalOut Vctl2(CRF2);
+ DigitalOut Vctl3(CRF3);
+
+ void rfsw_callback()
+ {
+ if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
+ Vctl1 = 0;
+ if (radio.RegPaConfig.bits.PaSelect) {
+ Vctl2 = 0;
+ Vctl3 = 1;
+ } else {
+ Vctl2 = 1;
+ Vctl3 = 0;
+ }
+ } else {
+ if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
+ Vctl1 = 1;
+ else
+ Vctl1 = 0;
+
+ Vctl2 = 0;
+ Vctl3 = 0;
+ }
+ }
+
+ DigitalOut pinA(PB_12);
+ DigitalOut pinB(PB_13);
+ DigitalOut pinC(PB_14);
+ DigitalOut pinD(PB_15);
+#else
+ SPI spi(D11, D12, D13); // mosi, miso, sclk
+ // dio0, dio1, nss, spi, rst
+ SX127x radio( D2, D3, D10, spi, A0); // sx1276 arduino shield
+
+ DigitalInOut rfsw(A4); // for SX1276 arduino shield
+
+ void rfsw_callback()
+ {
+ if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
+ rfsw = 1;
+ else
+ rfsw = 0;
+ }
+
+ DigitalOut pinA(PC_3);
+ DigitalOut pinB(PC_2);
+ DigitalOut pinC(PC_6);
+ DigitalOut pinD(PC_8);
+#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
+
+/**********************************************************************/
SX127x_lora lora(radio);
-DigitalInOut rfsw(A4); // for SX1276 arduino shield
-
-void rfsw_callback()
-{
- if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
- rfsw = 1;
- else
- rfsw = 0;
-}
-/**********************************************************************/
-DigitalOut pc3(PC_3);
-DigitalOut pc2(PC_2);
-DigitalOut pc6(PC_6);
-DigitalOut pc8(PC_8);
+
DigitalOut* pin;
Timeout to;
#define PIN_ASSERT_us 500000
-#define CMD_PC2 0x02
-#define CMD_PC3 0x03
-#define CMD_PC6 0x06
-#define CMD_PC8 0x08
+#define CMD_PINA 0x02
+#define CMD_PINB 0x03
+#define CMD_PINC 0x06
+#define CMD_PIND 0x08
void alarm_pin_clr()
{
@@ -76,7 +119,7 @@
if (crc == rx_crc) {
uint8_t c = radio.rx_buf[0];
//if (radio.rx_buf[0] == CMD_ALARM)
- if (c == CMD_PC2 || c == CMD_PC3 || c == CMD_PC6 || c == CMD_PC8) {
+ if (c == CMD_PINA || c == CMD_PINB || c == CMD_PINC || c == CMD_PIND) {
unsigned delay;
delay = radio.rx_buf[1];
delay <<= 8;
@@ -86,10 +129,10 @@
delay <<= 8;
delay += radio.rx_buf[4];
switch (c) {
- case CMD_PC2: pin = &pc2; break;
- case CMD_PC3: pin = &pc3; break;
- case CMD_PC6: pin = &pc6; break;
- case CMD_PC8: pin = &pc8; break;
+ case CMD_PINA: pin = &pinA; break;
+ case CMD_PINB: pin = &pinB; break;
+ case CMD_PINC: pin = &pinC; break;
+ case CMD_PIND: pin = &pinD; break;
}
to.attach_us(&alarm_pin_set, delay);
printf("delay:%u\r\n", delay);
@@ -109,6 +152,10 @@
lora.setBw_KHz(500);
lora.setSf(11);
+ radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
+#ifdef TARGET_DISCO_L072CZ_LRWAN1
+ radio.RegPaConfig.bits.PaSelect = 1;
+#else
/* RFO or PABOOST choice:
* SX1276 shield: RFO if using 900MHz, or PA_BOOST if using 433MHz
*/
@@ -126,6 +173,7 @@
printf("MAS\r\n");
}
rfsw.output();
+#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
lora.start_rx(RF_OPMODE_RECEIVER);