Author Topic: Real time RSSI measurement broken RFM69CW?  (Read 25104 times)

emjay

  • Full Member
  • ***
  • Posts: 120
  • Country: nl
Re: Real time RSSI measurement broken RFM69CW?
« Reply #30 on: January 22, 2016, 03:06:31 AM »
@WhiteHare,

Interesting indeed. Could you do a run with the ANT pin shorted to GND (ideally with ~50Ω SMD if you have one handy).

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #31 on: January 22, 2016, 07:43:44 AM »
I don't have a 50Ω SMD, but I probably have the equivalent ohms in regular resistors.  Shall I use that?

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #32 on: January 22, 2016, 09:39:21 AM »
The other salient finding is that there's generally roughly  a 15-20dB difference (though sometimes more and sometimes less) between the first reading, when RSSI flag is high and RxReady flag is still LOW, and subsequent readings when both are HIGH.  Almost invariably, that first measurement shows a higher dB (i.e. a less negative number) than the subsequent measurements taken in the same Rx cycle.

FWIW, the results are 100% repeatable.  I've tried it now with the same results on two different computers and with two different USB cables (one of which has a ferrite core on it).

I've also tried it on two different RFM69HW Moteino's (authentic official versions, assembled and soldered at LowPowerLabs, and purchased directly from LowPowerLabs), and the results are the same for both of them.
« Last Edit: January 22, 2016, 11:20:27 AM by WhiteHare »

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Real time RSSI measurement broken RFM69CW?
« Reply #33 on: January 22, 2016, 10:50:01 AM »
You're right, I didn't expect that result!

I think we're closing in on what's happening. I have just repeated your experiment with my own code, and have got exactly the same result. What I noticed though is that the RSSI value will continue to change after the RSSI interrupt without exiting RX mode, but will freeze as soon as a sync address match happens. In theory this could happen with noise, the probability is small and the payload ready is then extremely unlikely to fire due to the CRC mismatch, but if a sync address match ever does happen randomly the receiver will need to be restarted otherwise RSSI values get stuck. This would involve detecting a sync address match in the loop and restarting.

I've just implemented the above fix (i.e. only issue a restart when a sync address match happens, don't exit from RX mode at all in the loop) and it appears to work.

(BTW the way you enter RX and standby modes is not complete, once you've written to the OPMODE register you're supposed to poll the IRQFLAGS register and wait for the MODEREADY to go high to indicate that mode has been selected)
Mark.

emjay

  • Full Member
  • ***
  • Posts: 120
  • Country: nl
Re: Real time RSSI measurement broken RFM69CW?
« Reply #34 on: January 22, 2016, 12:41:46 PM »
@WhiteHare,

A tiny 47Ω discrete would be ok - the issue is avoiding creating much of a loop antenna. Then this (or if you have to, just a solder blob short) should give the noise floor of the Rx section. It's still noise of course, but the substantial spikes you are seeing can't happen, so if similar spikes are present it suggests strongly that the RSSI value strobed out is an artifact of the method.


WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #35 on: January 22, 2016, 12:49:18 PM »
If I switch to the default baudrate provided by Felix's code on both the node and the gateway, and after I power-up the node, then I get the results I would expect, except that reported RSSI seems to lag even after the PayloadReady bit in IrqFlags2 is first reported to have gone HIGH.  On the other hand, once the RSSI value catches up, it stays at that number on subsequent reads within the same Rx-cycle.

Here is an excerpt of the output which illustrates:

Code: [Select]
2177.0: regIrqFlags1=10011000, RSSI=-81, regIrqFlags2=0
2177.1: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2177.2: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
2177.3: regIrqFlags1=11011000, RSSI=-98, regIrqFlags2=1000110
2177.4: regIrqFlags1=11011001, RSSI=-43, regIrqFlags2=1000110
2177.5: regIrqFlags1=11011001, RSSI=-43, regIrqFlags2=1000110
2177.6: regIrqFlags1=11011001, RSSI=-43, regIrqFlags2=1000110
2177.7: regIrqFlags1=11011001, RSSI=-43, regIrqFlags2=1000110
2177.8: regIrqFlags1=11011001, RSSI=-43, regIrqFlags2=1000110
2177.9: regIrqFlags1=11011001, RSSI=-43, regIrqFlags2=1000110
2178.0: regIrqFlags1=10011000, RSSI=-83, regIrqFlags2=0
2178.1: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
2178.2: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
2178.3: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
2178.4: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2178.5: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
2178.6: regIrqFlags1=11011000, RSSI=-98, regIrqFlags2=0
2178.7: regIrqFlags1=11011000, RSSI=-92, regIrqFlags2=0
2178.8: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2178.9: regIrqFlags1=11011000, RSSI=-108, regIrqFlags2=0
2179.0: regIrqFlags1=10011000, RSSI=-81, regIrqFlags2=0
2179.1: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
2179.2: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2179.3: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
2179.4: regIrqFlags1=11011000, RSSI=-126, regIrqFlags2=0
2179.5: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
2179.6: regIrqFlags1=11011000, RSSI=-96, regIrqFlags2=0
2179.7: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
2179.8: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2179.9: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2180.0: regIrqFlags1=10011000, RSSI=-79, regIrqFlags2=0
2180.1: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
2180.2: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=1000110
2180.3: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2180.4: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2180.5: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2180.6: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2180.7: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2180.8: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2180.9: regIrqFlags1=11011001, RSSI=-44, regIrqFlags2=1000110
2181.0: regIrqFlags1=10011000, RSSI=-81, regIrqFlags2=0
2181.1: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
2181.2: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
2181.3: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
2181.4: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
2181.5: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
2181.6: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
2181.7: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
2181.8: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
2181.9: regIrqFlags1=11011000, RSSI=-97, regIrqFlags2=1000110
2182.0: regIrqFlags1=10011000, RSSI=-80, regIrqFlags2=0

@emjay I'll make an attempt on shorting the antenna and post the results.
« Last Edit: January 22, 2016, 12:55:26 PM by WhiteHare »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #36 on: January 22, 2016, 01:41:37 PM »
Oops.  It turns out the "lag" was actually just an artificat of the order in which I was reading the irqFlags.  I corrected it so that irqFlags2 is now read first, and now it matches what you would expect (though maybe there's some lag in the FIFO flags getting cleared, but that's not really consequential):

Reading the registers in this corrected order:
Code: [Select]
    regIrqFlags2 = radio.readReg(REG_IRQFLAGS2);
    regIrqFlags1 = radio.readReg(REG_IRQFLAGS1);
    theRSSI = -(radio.readReg(REG_RSSIVALUE))/2;

yields results like this:
Code: [Select]
441.0: regIrqFlags1=11011000, RSSI=-87, regIrqFlags2=0
441.1: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
441.2: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
441.3: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
441.4: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
441.5: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
441.6: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
441.7: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
441.8: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
441.9: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
442.0: regIrqFlags1=11011000, RSSI=-83, regIrqFlags2=1100000
442.1: regIrqFlags1=11011000, RSSI=-100, regIrqFlags2=0
442.2: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
442.3: regIrqFlags1=11011000, RSSI=-98, regIrqFlags2=0
442.4: regIrqFlags1=11011000, RSSI=-96, regIrqFlags2=0
442.5: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
442.6: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
442.7: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
442.8: regIrqFlags1=11011000, RSSI=-96, regIrqFlags2=0
442.9: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
443.0: regIrqFlags1=11011000, RSSI=-52, regIrqFlags2=0
443.1: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.2: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.3: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.4: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.5: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.6: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.7: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.8: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
443.9: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
444.0: regIrqFlags1=11011000, RSSI=-90, regIrqFlags2=1100000
444.1: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
444.2: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
444.3: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
444.4: regIrqFlags1=11011000, RSSI=-98, regIrqFlags2=0
444.5: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
444.6: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
444.7: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
444.8: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
444.9: regIrqFlags1=11011001, RSSI=-32, regIrqFlags2=1100110
445.0: regIrqFlags1=11011000, RSSI=-86, regIrqFlags2=1100000

Anyhow, the main point is that the early evidence seems to indicate that the RSSI value doesn't  latch unless payloadReady is HIGH.
« Last Edit: January 22, 2016, 01:52:26 PM by WhiteHare »

emjay

  • Full Member
  • ***
  • Posts: 120
  • Country: nl
Re: Real time RSSI measurement broken RFM69CW?
« Reply #37 on: January 22, 2016, 01:46:21 PM »
@WhiteHare - good work!   Determined prising at the shell will open this oyster eventually...

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #38 on: January 22, 2016, 02:20:18 PM »
You're right, I didn't expect that result!

I think we're closing in on what's happening. I have just repeated your experiment with my own code, and have got exactly the same result. What I noticed though is that the RSSI value will continue to change after the RSSI interrupt without exiting RX mode, but will freeze as soon as a sync address match happens. In theory this could happen with noise, the probability is small and the payload ready is then extremely unlikely to fire due to the CRC mismatch, but if a sync address match ever does happen randomly the receiver will need to be restarted otherwise RSSI values get stuck. This would involve detecting a sync address match in the loop and restarting.

I've just implemented the above fix (i.e. only issue a restart when a sync address match happens, don't exit from RX mode at all in the loop) and it appears to work.

(BTW the way you enter RX and standby modes is not complete, once you've written to the OPMODE register you're supposed to poll the IRQFLAGS register and wait for the MODEREADY to go high to indicate that mode has been selected)
Mark.

Regarding the syncAddressMatch, I think it's probably that way intentionally.  i.e. it's a feature, not a bug.  In my case (see most recent posting of results above), syncAddressMatch happens to go HIGH around the same time that PayloadReady goes HIGH.  Unfortunately, I don't have any cases (yet) where syncAddressMatch goes HIGH but not PayloadReady, so I'm not sure yet which one is essential for latching the RSSI value (or maybe it's neither but instead one of the other flags that goes HIGH around the same time).

[Edit: I looked a bit further and found an example that distinguishes between the two (see below):

Code: [Select]
460.0: regIrqFlags1=11011000, RSSI=-87, regIrqFlags2=0
460.1: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
460.2: regIrqFlags1=11011000, RSSI=-93, regIrqFlags2=0
460.3: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
460.4: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
460.5: regIrqFlags1=11011000, RSSI=-98, regIrqFlags2=0
460.6: regIrqFlags1=11011001, RSSI=-26, regIrqFlags2=1100000
460.7: regIrqFlags1=11011001, RSSI=-30, regIrqFlags2=1100110
460.8: regIrqFlags1=11011001, RSSI=-30, regIrqFlags2=1100110
460.9: regIrqFlags1=11011001, RSSI=-30, regIrqFlags2=1100110
461.0: regIrqFlags1=11011000, RSSI=-86, regIrqFlags2=1100000

So, it would appear it is not syncAddressMatch that does the latching.  Instead, it would appear that it's either PayloadReady or CrcOK that has to go HIGH in order for the RSSI value to latch.  Now I just need to find a similar case that will distinguish between those two....]
« Last Edit: January 22, 2016, 02:52:16 PM by WhiteHare »

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Real time RSSI measurement broken RFM69CW?
« Reply #39 on: January 22, 2016, 05:08:16 PM »
I've just tried putting the receiver into unlimited packet length mode and sampling the RSSI and the two flag registers into arrays within the 10 cycle loop. I kept the FIFO empty by reading when not empty it so as not to trigger a FIFO overflow condition, and this generates a sync address match but with no payload ready.

I can confirm your hypothesis, it appears sync address match does not freeze the RSSI measurements, it must be payloadReady or crcOk. The RSSI measurements continually updated even though syncAddressMatch stayed active until it was reset. However, a lot of the time they didn't seem to be the correct RSSI values! Some of the values were correct (and changed by relatively small amounts around that value within the loop), others were widely off.

Mark.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #40 on: January 22, 2016, 11:13:07 PM »
I unsoldered Felix's wire antenna and then soldered on a 47 ohm resistor to short antenna to ground (see attached photo).  After doing so, here are the results from using the latest version of the sketch:

Code: [Select]
2.0: regIrqFlags1=11011000, RSSI=-86, regIrqFlags2=0
2.1: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
2.2: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
2.3: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
2.4: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
2.5: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
2.6: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
2.7: regIrqFlags1=11011000, RSSI=-108, regIrqFlags2=0
2.8: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
2.9: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
3.0: regIrqFlags1=11011000, RSSI=-89, regIrqFlags2=0
3.1: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
3.2: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
3.3: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
3.4: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
3.5: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
3.6: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
3.7: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
3.8: regIrqFlags1=11011000, RSSI=-110, regIrqFlags2=0
3.9: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
4.0: regIrqFlags1=11011000, RSSI=-86, regIrqFlags2=0
4.1: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
4.2: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
4.3: regIrqFlags1=11011000, RSSI=-109, regIrqFlags2=0
4.4: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
4.5: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
4.6: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
4.7: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
4.8: regIrqFlags1=11011001, RSSI=-104, regIrqFlags2=1000000
4.9: regIrqFlags1=11011000, RSSI=-112, regIrqFlags2=0
5.0: regIrqFlags1=11011000, RSSI=-88, regIrqFlags2=0
5.1: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
5.2: regIrqFlags1=11011000, RSSI=-113, regIrqFlags2=0
5.3: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
5.4: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
5.5: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
5.6: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
5.7: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
5.8: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
5.9: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
6.0: regIrqFlags1=11011000, RSSI=-88, regIrqFlags2=0
6.1: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
6.2: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
6.3: regIrqFlags1=11011000, RSSI=-115, regIrqFlags2=0
6.4: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
6.5: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
6.6: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
6.7: regIrqFlags1=11011000, RSSI=-108, regIrqFlags2=0
6.8: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
6.9: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
7.0: regIrqFlags1=11011000, RSSI=-94, regIrqFlags2=0
7.1: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
7.2: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
7.3: regIrqFlags1=11011000, RSSI=-102, regIrqFlags2=0
7.4: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
7.5: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
7.6: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
7.7: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
7.8: regIrqFlags1=11011000, RSSI=-107, regIrqFlags2=0
7.9: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0
8.0: regIrqFlags1=11011000, RSSI=-86, regIrqFlags2=0
8.1: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
8.2: regIrqFlags1=11011000, RSSI=-114, regIrqFlags2=0
8.3: regIrqFlags1=11011000, RSSI=-99, regIrqFlags2=0
8.4: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
8.5: regIrqFlags1=11011000, RSSI=-98, regIrqFlags2=0
8.6: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
8.7: regIrqFlags1=11011000, RSSI=-103, regIrqFlags2=0
8.8: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
8.9: regIrqFlags1=11011000, RSSI=-101, regIrqFlags2=0

What do you think it all means?

Here's the sketch:
Code: [Select]
//Version 3.1

// Sample RFM69 receiver/gateway sketch, with ACK and optional encryption
// Passes through any wireless received messages to the serial port & responds to ACKs
// It also looks for an onboard FLASH chip, if present
// Library and code by Felix Rusu - felix@lowpowerlab.com
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/

#include <RFM69.h>    //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash
#include <RFM69registers.h>

#define NODEID        1    //unique for each node on same network
#define NETWORKID     100  //the same on all nodes that talk to each other
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY     RF69_915MHZ
#define ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define SERIAL_BAUD   250000

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

RFM69 radio;
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network

void setup() {
  Serial.begin(SERIAL_BAUD);
  delay(10);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
  radio.setHighPower(); //only for RFM69HW!
#endif
  radio.encrypt(ENCRYPTKEY);
  radio.promiscuous(promiscuousMode);
   
  //radio.writeReg(REG_BITRATEMSB, RF_BITRATEMSB_300000);  //set MSB bitrate to 300Kbps
  //radio.writeReg(REG_BITRATELSB, RF_BITRATELSB_300000);  //set LSB bitrate to 300Kbps
  //Serial.println(F("Bitrate set to 300Kbps."));
  Serial.println(F("Default bitrate."));
 
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  if (flash.initialize())
  {
    Serial.print("SPI Flash Init OK. Unique MAC = [");
    flash.readUniqueId();
    for (byte i=0;i<8;i++)
    {
      Serial.print(flash.UNIQUEID[i], HEX);
      if (i!=8) Serial.print(':');
    }
    Serial.println(']');
   
    //alternative way to read it:
    //byte* MAC = flash.readUniqueId();
    //for (byte i=0;i<8;i++)
    //{
    //  Serial.print(MAC[i], HEX);
    //  Serial.print(' ');
    //}
   
  }
  else
    Serial.println("SPI Flash Init FAIL! (is chip present?)");

  radio.writeReg(REG_OPMODE, (radio.readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_STANDBY);  //set standby-mode
  radio.writeReg(REG_RSSITHRESH, 0xFF);  //set RSSI threshhold as low as possible
  radio.writeReg(REG_OPMODE, (radio.readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_RECEIVER);  //set Rx-mode   
}
long loopCount=0;
int theRSSI;
int maxRSSI= (-125);
uint8_t regIrqFlags1, regIrqFlags2;

void loop() {
  loopCount++;
 
  while (!(radio.readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_RSSI)) { //busy-wait until RSSI flag goes HIGH
  }

  for (int i=0;i<10; i++) {
    regIrqFlags2 = radio.readReg(REG_IRQFLAGS2);
    regIrqFlags1 = radio.readReg(REG_IRQFLAGS1);
    theRSSI = -(radio.readReg(REG_RSSIVALUE))/2;

    if ((theRSSI > maxRSSI)) {
      maxRSSI = theRSSI;
    }
 
    Serial.print(loopCount);Serial.print(F("."));Serial.print(i);
    Serial.print(F(": regIrqFlags1="));Serial.print((regIrqFlags1),BIN);
    Serial.print(F(", RSSI=")); Serial.print(theRSSI);
    Serial.print(F(", regIrqFlags2="));Serial.println((regIrqFlags2),BIN);
  }

  radio.writeReg(REG_OPMODE, (radio.readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_STANDBY);  //set standby-mode
  radio.writeReg(REG_OPMODE, (radio.readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_RECEIVER);  //set Rx-mode
}



I can see how using an SMD resistor would have been ideal.  Unfortunately, I don't have any on-hand.  If anyone else does, feel free to repeat the test using that together with the same sketch, and then post.
« Last Edit: January 23, 2016, 12:28:35 AM by WhiteHare »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #41 on: January 23, 2016, 12:22:47 AM »
I've just tried putting the receiver into unlimited packet length mode and sampling the RSSI and the two flag registers into arrays within the 10 cycle loop. I kept the FIFO empty by reading when not empty it so as not to trigger a FIFO overflow condition, and this generates a sync address match but with no payload ready.

I can confirm your hypothesis, it appears sync address match does not freeze the RSSI measurements, it must be payloadReady or crcOk. The RSSI measurements continually updated even though syncAddressMatch stayed active until it was reset. However, a lot of the time they didn't seem to be the correct RSSI values! Some of the values were correct (and changed by relatively small amounts around that value within the loop), others were widely off.

Mark.

I disabled CRC and re-ran the earlier test using a regular Moteino (not the one with the shorted antenna above).  The results show that PayloadReady is the essential flag for latching the RSSI value:

Code: [Select]
796.0: regIrqFlags1=11011000, RSSI=-82, regIrqFlags2=0
796.1: regIrqFlags1=11011000, RSSI=-105, regIrqFlags2=0
796.2: regIrqFlags1=11011000, RSSI=-106, regIrqFlags2=0
796.3: regIrqFlags1=11011000, RSSI=-104, regIrqFlags2=0
796.4: regIrqFlags1=11011001, RSSI=-39, regIrqFlags2=1000100
796.5: regIrqFlags1=11011001, RSSI=-39, regIrqFlags2=1000100
796.6: regIrqFlags1=11011001, RSSI=-39, regIrqFlags2=1000100
796.7: regIrqFlags1=11011001, RSSI=-39, regIrqFlags2=1000100
796.8: regIrqFlags1=11011001, RSSI=-39, regIrqFlags2=1000100
796.9: regIrqFlags1=11011001, RSSI=-39, regIrqFlags2=1000100
797.0: regIrqFlags1=11011000, RSSI=-83, regIrqFlags2=1000000

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #42 on: January 23, 2016, 03:54:10 AM »
For the moment, I removed flagsIrq2 from consideration and ran the latest version (version 4.0) of the sketch on the Moteino whose antenna is nominally shorted.  BTW, it now uses RxRestart in the main loop.

I also turned on the transmitter and found that even with the antenna "shorted," it was still receiving some packets:

Code: [Select]
1.0: regIrqFlags1=10011000, RSSI=-82
1.1: regIrqFlags1=11011000, RSSI=-101
1.2: regIrqFlags1=11011000, RSSI=-102
1.3: regIrqFlags1=11011000, RSSI=-109
1.4: regIrqFlags1=11011000, RSSI=-104
1.5: regIrqFlags1=11011000, RSSI=-107
1.6: regIrqFlags1=11011000, RSSI=-111
1.7: regIrqFlags1=11011000, RSSI=-101
1.8: regIrqFlags1=11011000, RSSI=-109
1.9: regIrqFlags1=11011000, RSSI=-105
2.0: regIrqFlags1=10011000, RSSI=-81
2.1: regIrqFlags1=11011000, RSSI=-103
2.2: regIrqFlags1=11011001, RSSI=-56
2.3: regIrqFlags1=11011001, RSSI=-58
2.4: regIrqFlags1=11011001, RSSI=-58
2.5: regIrqFlags1=11011001, RSSI=-58
2.6: regIrqFlags1=11011001, RSSI=-58
2.7: regIrqFlags1=11011001, RSSI=-58
2.8: regIrqFlags1=11011001, RSSI=-58
2.9: regIrqFlags1=11011001, RSSI=-58
3.0: regIrqFlags1=10011000, RSSI=-77
3.1: regIrqFlags1=11011000, RSSI=-102
3.2: regIrqFlags1=11011000, RSSI=-104
3.3: regIrqFlags1=11011000, RSSI=-107
3.4: regIrqFlags1=11011000, RSSI=-107
3.5: regIrqFlags1=11011000, RSSI=-107
3.6: regIrqFlags1=11011000, RSSI=-100
3.7: regIrqFlags1=11011000, RSSI=-110
3.8: regIrqFlags1=11011000, RSSI=-102
3.9: regIrqFlags1=11011000, RSSI=-105
4.0: regIrqFlags1=10011000, RSSI=-81
4.1: regIrqFlags1=11011000, RSSI=-105
4.2: regIrqFlags1=11011000, RSSI=-99
4.3: regIrqFlags1=11011000, RSSI=-103
4.4: regIrqFlags1=11011000, RSSI=-104
4.5: regIrqFlags1=11011000, RSSI=-100
4.6: regIrqFlags1=11011000, RSSI=-102
4.7: regIrqFlags1=11011000, RSSI=-107
4.8: regIrqFlags1=11011000, RSSI=-101
4.9: regIrqFlags1=11011001, RSSI=-58
5.0: regIrqFlags1=10011000, RSSI=-76
5.1: regIrqFlags1=11011000, RSSI=-105
5.2: regIrqFlags1=11011000, RSSI=-101
5.3: regIrqFlags1=11011000, RSSI=-104
5.4: regIrqFlags1=11011000, RSSI=-103
5.5: regIrqFlags1=11011000, RSSI=-109
5.6: regIrqFlags1=11011000, RSSI=-105
5.7: regIrqFlags1=11011000, RSSI=-104
5.8: regIrqFlags1=11011000, RSSI=-108
5.9: regIrqFlags1=11011000, RSSI=-102
6.0: regIrqFlags1=10011000, RSSI=-81
6.1: regIrqFlags1=11011000, RSSI=-107
6.2: regIrqFlags1=11011000, RSSI=-107
6.3: regIrqFlags1=11011000, RSSI=-106
6.4: regIrqFlags1=11011000, RSSI=-108
6.5: regIrqFlags1=11011000, RSSI=-102
6.6: regIrqFlags1=11011000, RSSI=-103
6.7: regIrqFlags1=11011000, RSSI=-103
6.8: regIrqFlags1=11011000, RSSI=-103
6.9: regIrqFlags1=11011000, RSSI=-110
7.0: regIrqFlags1=10011000, RSSI=-82
7.1: regIrqFlags1=11011000, RSSI=-106
7.2: regIrqFlags1=11011000, RSSI=-105
7.3: regIrqFlags1=11011000, RSSI=-102
7.4: regIrqFlags1=11011000, RSSI=-101
7.5: regIrqFlags1=11011001, RSSI=-54
7.6: regIrqFlags1=11011001, RSSI=-57
7.7: regIrqFlags1=11011001, RSSI=-57
7.8: regIrqFlags1=11011001, RSSI=-57
7.9: regIrqFlags1=11011001, RSSI=-57
8.0: regIrqFlags1=10011000, RSSI=-77
8.1: regIrqFlags1=11011000, RSSI=-103
8.2: regIrqFlags1=11011000, RSSI=-105
8.3: regIrqFlags1=11011000, RSSI=-107
8.4: regIrqFlags1=11011000, RSSI=-109
8.5: regIrqFlags1=11011000, RSSI=-109
8.6: regIrqFlags1=11011000, RSSI=-103
8.7: regIrqFlags1=11011000, RSSI=-101
8.8: regIrqFlags1=11011000, RSSI=-107
8.9: regIrqFlags1=11011000, RSSI=-111
9.0: regIrqFlags1=10011000, RSSI=-82
9.1: regIrqFlags1=11011000, RSSI=-107
9.2: regIrqFlags1=11011000, RSSI=-105
9.3: regIrqFlags1=11011000, RSSI=-106
9.4: regIrqFlags1=11011000, RSSI=-102
9.5: regIrqFlags1=11011000, RSSI=-105
9.6: regIrqFlags1=11011000, RSSI=-107
9.7: regIrqFlags1=11011000, RSSI=-103
9.8: regIrqFlags1=11011000, RSSI=-105
9.9: regIrqFlags1=11011000, RSSI=-107
10.0: regIrqFlags1=10011000, RSSI=-82

Here's the current sketch which produced the above results:
Code: [Select]
//Version 4.0

// Sample RFM69 receiver/gateway sketch, with ACK and optional encryption
// Passes through any wireless received messages to the serial port & responds to ACKs
// It also looks for an onboard FLASH chip, if present
// Library and code by Felix Rusu - felix@lowpowerlab.com
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/

#include <RFM69.h>    //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash
#include <RFM69registers.h>

#define NODEID        1    //unique for each node on same network
#define NETWORKID     100  //the same on all nodes that talk to each other
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY     RF69_915MHZ
#define ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define SERIAL_BAUD   250000

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

RFM69 radio;
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network
uint8_t oldRegPacketConfig1,newRegPacketConfig1;
uint8_t oldPacketConfig2, newPacketConfig2;

void setup() {
  Serial.begin(SERIAL_BAUD);
  delay(10);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
  radio.setHighPower(); //only for RFM69HW!
#endif
  radio.encrypt(ENCRYPTKEY);
  radio.promiscuous(promiscuousMode);
   
  //radio.writeReg(REG_BITRATEMSB, RF_BITRATEMSB_300000);  //set MSB bitrate to 300Kbps
  //radio.writeReg(REG_BITRATELSB, RF_BITRATELSB_300000);  //set LSB bitrate to 300Kbps
  //Serial.println(F("Bitrate set to 300Kbps."));
  Serial.println(F("Default bitrate."));
 
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  if (flash.initialize())
  {
    Serial.print("SPI Flash Init OK. Unique MAC = [");
    flash.readUniqueId();
    for (byte i=0;i<8;i++)
    {
      Serial.print(flash.UNIQUEID[i], HEX);
      if (i!=8) Serial.print(':');
    }
    Serial.println(']');
   
    //alternative way to read it:
    //byte* MAC = flash.readUniqueId();
    //for (byte i=0;i<8;i++)
    //{
    //  Serial.print(MAC[i], HEX);
    //  Serial.print(' ');
    //}
   
  }
  else
    Serial.println("SPI Flash Init FAIL! (is chip present?)");

  //oldRegPacketConfig1 = radio.readReg(REG_PACKETCONFIG1);
  //newRegPacketConfig1 = oldRegPacketConfig1 & ((RF_PACKET1_CRC_ON)^0xFF); //clear CRC_ON bit
   
  radio.writeReg(REG_OPMODE, (radio.readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_STANDBY);  //set standby-mode
  radio.writeReg(REG_RSSITHRESH, 0xFF);  //set RSSI threshhold as low as possible
  //radio.writeReg(REG_PACKETCONFIG1,newRegPacketConfig1);  //disable CRC checking
  radio.writeReg(REG_OPMODE, (radio.readReg(REG_OPMODE) & 0xE3) | RF_OPMODE_RECEIVER);  //set Rx-mode   
}


long loopCount=0;
int theRSSI;
int maxRSSI= (-125);
uint8_t regIrqFlags1, regIrqFlags2;

void loop() {
  loopCount++;
 
  while (!(radio.readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_RSSI)) { //busy-wait until RSSI flag goes HIGH
  }

  for (int i=0;i<10; i++) {
    //regIrqFlags2 = radio.readReg(REG_IRQFLAGS2);
    regIrqFlags1 = radio.readReg(REG_IRQFLAGS1);
    theRSSI = -(radio.readReg(REG_RSSIVALUE))/2;

    //if ((theRSSI > maxRSSI)) {
      //maxRSSI = theRSSI;
    //}
 
    Serial.print(loopCount);Serial.print(F("."));Serial.print(i);
    Serial.print(F(": regIrqFlags1="));Serial.print((regIrqFlags1),BIN);
    Serial.print(F(", RSSI=")); Serial.println(theRSSI);
    //Serial.print(F(", regIrqFlags2="));Serial.println((regIrqFlags2),BIN);
  }

  oldPacketConfig2 = radio.readReg(REG_PACKETCONFIG2);
  newPacketConfig2 = (oldPacketConfig2 | RF_PACKET2_RXRESTART); //set RxRestart bit
  radio.writeReg(REG_PACKETCONFIG2,newPacketConfig2); //transition to Rx-WAIT mode
}

So, here are my conclusions:
1.  Obviously, some external RF is getting into the system, even with a "shorted" antenna.  So, that may explain, either fully or in-part, the varying RSSI.
2.  If you want to measure RSSI, wait until the RxReady flag goes HIGH.  The RSSI measured after the RSSI flag goes HIGH but before the RxReady flag goes HIGH seems less accurate. 

What are your conclusions?

emjay

  • Full Member
  • ***
  • Posts: 120
  • Country: nl
Re: Real time RSSI measurement broken RFM69CW?
« Reply #43 on: January 23, 2016, 07:44:49 AM »
@WhiteHare,

Those ~20dB RSSI jumps are difficult to explain - I was hoping that with the 'null' input, they would disappear. Then it is reasonable to conclude that at least the jumps are external RF (and hence unavoidable), not an artifact of RSSI measurement/strobing.

To track this down further would need something like enclosing the entire UIT in a metal box - harder than it seems since any wires into the box need extensive decoupling.  The result does echo one of your previous threads though - UHF penetrates amazingly well, even into the traces/components between the ANT pin and the RFIO pin on the chip.  If you want to chase the limits of range (LoRa or classic), it is worth paying a lot of attention to screening/isolation of the super sensitive Rx front end.  If not, the desired signal is just wallowing in excessive noise.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Real time RSSI measurement broken RFM69CW?
« Reply #44 on: January 23, 2016, 09:36:04 PM »
To further "null" the input, I suppose one could run the Moteino on batteries and then put the entire thing inside a closed metal box, have it record some measurements into either an array or the memory chip for later playback, and then play the measurements back after opening up the box again.