2021-09-04 06:41 AM
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.
Solved! Go to Solution.
2021-09-04 07:09 AM
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));
}
2021-09-04 07:01 AM
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.
2021-09-04 07:09 AM
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));
}
2021-09-04 07:24 AM
More simply, the integer math here for MHz
F = (freq * 524288)>>5;
Could be this for freq in integer Hz in floating point, where you pass in 433663000
F = (int)((float)freq / 61.03515625f);
or
void LoRa_setFrequency(LoRa* _LoRa, float freq)
{
uint8_t data; uint32_t F;
F = (uint32_t)(freq * 1e6 / 61.03515625f);
..
}
Called as LoRa_setFrequency(lora, 433.663)