@@ -24,7 +24,7 @@ Code porting from LoRa library https://github.dev/thekakester/Arduino-LoRa-Sx126
2424
2525static 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
2929const GpioPin * const pin_beacon = & gpio_swclk ;
3030const GpioPin * const pin_nss1 = & gpio_ext_pc0 ;
@@ -41,6 +41,7 @@ uint32_t pllFrequency;
4141uint8_t bandwidth ;
4242uint8_t codingRate ;
4343uint8_t spreadingFactor ;
44+ uint16_t syncWord ;
4445uint8_t lowDataRateOptimize ;
4546uint32_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-
127114uint32_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
584607The higher the spreading factor, the slower and more reliable the transmission will be. */
585608bool configSetSpreadingFactor (int sf ) {
0 commit comments