iwanders / plainRFM69

A library for the RFM69 radio module.
MIT License
32 stars 12 forks source link

868MHz frequency does not work #12

Open sheinz opened 4 years ago

sheinz commented 4 years ago

Hi, I have RFM69CW 868MHz modules. Trying them with unchanged "MinimalInterruptUno" example works fine. But after changing frequency to 868MHz the example stops working.

    rfm.setFrequency((uint32_t) 868*1000*1000); // set the frequency.

Any help is much appreciated.

Pablo2048 commented 4 years ago

Hi, you can try

rfm.setFrequency(868UL*1000*1000); // set the frequency
sheinz commented 4 years ago

Hi Pablo, I tried with no difference. I also tried setting frequency registers directly (without conversion):

    // rfm.setFrf(0x4EC000);  // 315MHz - works
    // rfm.setFrf(0x6C8000);  // 434MHz - works
    // rfm.setFrf(0xE4C000);  // 915MHz - doesn't work
    // rfm.setFrf(0xd90000);  // 868MHz - doesn't work
Pablo2048 commented 4 years ago

Is your CPU little endian?

sheinz commented 4 years ago

It is Arduino Pro mini, ATmega328p 16MHz, 3.3v. The Internet says it is little endian.

Pablo2048 commented 4 years ago

Hmm, that is weird - I'm also using ATmega328p, RFM69@868MHz with no problem...

sheinz commented 4 years ago

Setting baud rate for RFM69 module other than 4800 (which is default) fixed the problem.

    // rfm.baud4800();    // doesn't work with 868MHz
    // rfm.baud9600();    // works with 868MHz but with high packet loss
    // rfm.baud153600();  // works with 868Mhz with no packet loss
    rfm.baud300000();     // works with 868MHz with no packet loss

153600 and 300000 works reliably with 868MHz modules.

iwanders commented 4 years ago

Hmm, I can definitely see setFrequency failing, the signature is:

void setFrequency(uint32_t freq);

So any value about 32 bits will get truncated. I developed this library against the 315 or 434 MHz version... clearly. Does an arduino support uint64_ts? Because if so we should probably just change the type, that should solve the issue? If anyone can test this and file a PR that'd be much appreciated, I don't have access to this hardware anymore.

@Pablo2048 , are you sure you are setting the frequency with setFrequency on your 868 MHz unit? Because the default values for the register should be good on each unit, but setting them should cause problems :)

The setFrf function should always work if the endianness of the cpu is right. It just copies the 3 relevant bytes from the input.

Setting baud rate for RFM69 module other than 4800 (which is default) fixed the problem.

Cool! Could have had something to do with needing a higher Fdev or something at these higher frequencies. The carrier is now probably set by the default value in the register, which should be fine in general.

Pablo2048 commented 4 years ago

Ehm, sorry for confusing - I take a look into my code and i'm not calling setFrequency...

iwanders commented 4 years ago

Hi,

I've filed #13 , I cannot test this unfortunately. @Pablo2048 , @sheinz if you have time, could you give that branch a spin and see if that allows you to make a call to setFrequency with a high number and end up with working communication?

Thanks!