Skip to main content
TEngi.2
Visitor II
September 4, 2021
Solved

STM32F446RE Setting Frequency with RFM98PW LoRa Module

Hi Everyone!

We have two RFM98PW LoRa Modules and we successfully can communicate with these modules from more than 9 kilometers. But when we change our frequency from 434 to about 433.663 we cannot communicate very well. It just *****. Using these LoRa modules with an Atmega2560 and STM32F446RET6. In Atmega, so in library that we are using setFrequency function to change frequency. Is it enough to change freq with just a function. Do we need to change anything else like bandwidth?

When we change the frequency the frequency error jumps to 32 kHz from 1 kHz in the receiver serial port.

Library: https://github.com/SMotlaq/LoRa

Thanks.

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
September 4, 2021

From the code in the LRWAN libraries

/*!
 * SX1276 definitions
 */
#define XTAL_FREQ 32000000
#define FREQ_STEP 61.03515625
#define FREQ_STEP_8 15625 /* FREQ_STEP<<8 */
 
 
/* channel = Freq / FREQ_STEP */
#define SX_FREQ_TO_CHANNEL( channel, freq ) \
 do \
 { \
 uint32_t initialFreqInt, initialFreqFrac; \
 initialFreqInt = freq / FREQ_STEP_8; \
 initialFreqFrac = freq - ( initialFreqInt * FREQ_STEP_8 ); \
 channel = ( initialFreqInt << 8 ) + ( ( ( initialFreqFrac << 8 ) + ( FREQ_STEP_8 / 2 ) ) / FREQ_STEP_8 ); \
 }while( 0 )
 
 
void SX1276SetChannel(uint32_t freq)
{
 uint32_t channel;
 
 SX1276.Settings.Channel = freq;
 
 SX_FREQ_TO_CHANNEL(channel, freq);
 
 SX1276Write(REG_FRFMSB, (uint8_t)((channel >> 16) & 0xFF));
 SX1276Write(REG_FRFMID, (uint8_t)((channel >> 8) & 0xFF));
 SX1276Write(REG_FRFLSB, (uint8_t)(channel & 0xFF));
}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

3 replies

Tesla DeLorean
Guru
September 4, 2021

Not sure I see that function in the repository, but it is using an integer in the structure holding MHz

Perhaps cite files/lines

https://github.com/SMotlaq/LoRa/blob/master/LoRa/LoRa.c#L152

https://github.com/SMotlaq/LoRa/blob/master/LoRa/LoRa.c#L22

I think the resolution of the Semtech libraries is significantly better, the registers are 24-bit, and the pass Hz at the library level. The 32-bit integers of the STM32 shouldn't have any issue with that resolution.

Assuming you're using this in a point-to-point mode.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
September 4, 2021

From the code in the LRWAN libraries

/*!
 * SX1276 definitions
 */
#define XTAL_FREQ 32000000
#define FREQ_STEP 61.03515625
#define FREQ_STEP_8 15625 /* FREQ_STEP<<8 */
 
 
/* channel = Freq / FREQ_STEP */
#define SX_FREQ_TO_CHANNEL( channel, freq ) \
 do \
 { \
 uint32_t initialFreqInt, initialFreqFrac; \
 initialFreqInt = freq / FREQ_STEP_8; \
 initialFreqFrac = freq - ( initialFreqInt * FREQ_STEP_8 ); \
 channel = ( initialFreqInt << 8 ) + ( ( ( initialFreqFrac << 8 ) + ( FREQ_STEP_8 / 2 ) ) / FREQ_STEP_8 ); \
 }while( 0 )
 
 
void SX1276SetChannel(uint32_t freq)
{
 uint32_t channel;
 
 SX1276.Settings.Channel = freq;
 
 SX_FREQ_TO_CHANNEL(channel, freq);
 
 SX1276Write(REG_FRFMSB, (uint8_t)((channel >> 16) & 0xFF));
 SX1276Write(REG_FRFMID, (uint8_t)((channel >> 8) & 0xFF));
 SX1276Write(REG_FRFLSB, (uint8_t)(channel & 0xFF));
}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..