Skip to content

Commit ccb9361

Browse files
authored
Merge pull request #6 from ElectronicCats/syncword
Add option to select sync word
2 parents 8399216 + 25501f3 commit ccb9361

File tree

3 files changed

+119
-52
lines changed

3 files changed

+119
-52
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
sdk-channel: release
1717
app-dir: ./applications_user/lora_app
1818
- name: Upload app artifacts
19-
uses: actions/upload-artifact@v3
19+
uses: actions/upload-artifact@v4
2020
with:
2121
name: ${{ github.event.repository.name }}-${{ steps.build-app.outputs.suffix }}
2222
path: ${{ steps.build-app.outputs.fap-artifacts }}

applications_user/lora_app/lora.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Code porting from LoRa library https://github.dev/thekakester/Arduino-LoRa-Sx126
2424

2525
static uint32_t timeout = 1000;
2626
//static uint32_t timeout = 100;
27-
static FuriHalSpiBusHandle* spi = &furi_hal_spi_bus_handle_external;
27+
static const FuriHalSpiBusHandle* spi = &furi_hal_spi_bus_handle_external;
2828

2929
const GpioPin* const pin_beacon = &gpio_swclk;
3030
const GpioPin* const pin_nss1 = &gpio_ext_pc0;
@@ -41,6 +41,7 @@ uint32_t pllFrequency;
4141
uint8_t bandwidth;
4242
uint8_t codingRate;
4343
uint8_t spreadingFactor;
44+
uint16_t syncWord;
4445
uint8_t lowDataRateOptimize;
4546
uint32_t transmitTimeout; //Worst-case transmit time depends on some factors
4647

@@ -110,20 +111,6 @@ uint8_t readRegister(uint16_t address) {
110111
return data;
111112
}
112113

113-
uint16_t getSyncWord() {
114-
uint8_t msb, lsb;
115-
uint16_t syncword;
116-
msb = readRegister(REG_LR_SYNCWORD);
117-
lsb = readRegister(REG_LR_SYNCWORD + 1);
118-
119-
FURI_LOG_E(TAG, "MSB: %02x", msb);
120-
FURI_LOG_E(TAG, "LSB: %02x", lsb);
121-
122-
syncword = (msb << 8) + lsb;
123-
124-
return syncword;
125-
}
126-
127114
uint32_t getFreqInt() {
128115
//get the current set device frequency from registers, return as long integer
129116

@@ -580,6 +567,42 @@ bool configSetCodingRate(int cr) {
580567
return true;
581568
}
582569

570+
/* Set the sync word*/
571+
bool configSetSyncWord(uint16_t sw) {
572+
uint8_t msb = (sw >> 8) & 0xFF;
573+
uint8_t lsb = sw & 0xFF;
574+
575+
// Write MSB to 0x0740
576+
furi_hal_gpio_write(pin_nss1, false); // CS low
577+
furi_hal_spi_acquire(spi);
578+
579+
spiBuff[0] = 0x0D; // WriteRegister opcode
580+
spiBuff[1] = 0x07; // Address high byte (0x0740)
581+
spiBuff[2] = 0x40; // Address low byte
582+
spiBuff[3] = msb; // Data
583+
furi_hal_spi_bus_tx(spi, spiBuff, 4, timeout);
584+
585+
furi_hal_spi_release(spi);
586+
furi_hal_gpio_write(pin_nss1, true); // CS high
587+
588+
// Write LSB to 0x0741
589+
furi_hal_gpio_write(pin_nss1, false); // CS low
590+
furi_hal_spi_acquire(spi);
591+
592+
spiBuff[0] = 0x0D; // WriteRegister opcode
593+
spiBuff[1] = 0x07; // Address high byte (0x0741)
594+
spiBuff[2] = 0x41; // Address low byte
595+
spiBuff[3] = lsb; // Data
596+
furi_hal_spi_bus_tx(spi, spiBuff, 4, timeout);
597+
598+
furi_hal_spi_release(spi);
599+
furi_hal_gpio_write(pin_nss1, true); // CS high
600+
601+
furi_delay_ms(1); // give chip time
602+
603+
return true;
604+
}
605+
583606
/* Change the spreading factor of a packet
584607
The higher the spreading factor, the slower and more reliable the transmission will be. */
585608
bool configSetSpreadingFactor(int sf) {

0 commit comments

Comments
 (0)