Skip to content

Fix power and frequency initiailzations #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 8, 2018
Merged

Fix power and frequency initiailzations #4

merged 11 commits into from
May 8, 2018

Conversation

jerryneedell
Copy link
Contributor

Most of the changes were to make this driver compatible with the Arduino driver.
The main changes are to the way the frequency was set - the actual "setter" was never being called and the default frequency (424mHz) remained the actual setting. In addition there was an error in calculation of the frequency setting due to the use of "//" vs "/".

The default baudrate of 10Mhz was causing some "hangs" during reads from the FIFO, even with a featherwing. Lowering it to 5MHz seems to have mad this much more reliable

Several minor changes were made bring the code to closer agreement with the Arduino dirver.

Added an arbitrary 2 second timeout to the send function. It may be changed va a keyword argument. but I wanted to avoid possible infinite loop.

Before these changes, two devices running CP could communicate, but they could not communicate to a device using Arduino. This was due to the frequency mis-configuration. The two CP devices were consistent with eachother, but not with the Arduino Driver.

Also renamed the example to rfm9x_simpletest as is the new custom.

I have tested this with rfm9x feathewings connnected to feather_m0_express boards running teh current CP3.0 master.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these improvements @jerryneedell ! Just a couple small comments before we merge.

timed_out = False
while not timed_out and not self.tx_done:
if (time.monotonic() - start) >= timeout_s:
timed_out = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please throw a RuntimeException in the case where tx_done is still false.

@@ -523,10 +534,11 @@ def rssi(self):
# Remember in LoRa mode the payload register changes function to RSSI!
return self._read_u8(_RH_RF95_REG_1A_PKT_RSSI_VALUE) - 137

def send(self, data):
def send(self, data, timeout_s=2.):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No _s. Just document that its in seconds. This should be our standard for timeouts. (time.sleep is an example of the same units.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - this was just a holdover from the original code. The change makes sense to me.

return None # Exceeded timeout.
# Clear interrupt.
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF)
timed_out = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception here too and it'll "return" early so you don't need the extra state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, there is still code that needs to execute after the timeout.
More importantly, I don't think we want an exception here. The typical use of receive it to see if any packets are available. A timeout is normal here.

We could break this into two parts like it is for Arduino and have an "available" function that the user polls until a packet is received.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, returning None is fine with me. I believe we do want an exception for send failure above though.

@@ -494,6 +498,10 @@ def tx_power(self):
high power devices (RFM95/96/97/98, high_power=True) or -1 to 14 for low
power devices. Only integer power levels are actually set (i.e. 12.5
will result in a value of 12 dBm).
The actual maximum setting for high_power=True is 20dBm but for values > 20
the PA_BOOST will be enabled resultiung in ad additonla gain of 3dBm.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh...My fingers are usually way ahead of my brain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, happens to me too. No worries. :-)

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thoughtful responses.

@@ -494,6 +498,10 @@ def tx_power(self):
high power devices (RFM95/96/97/98, high_power=True) or -1 to 14 for low
power devices. Only integer power levels are actually set (i.e. 12.5
will result in a value of 12 dBm).
The actual maximum setting for high_power=True is 20dBm but for values > 20
the PA_BOOST will be enabled resultiung in ad additonla gain of 3dBm.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, happens to me too. No worries. :-)

return None # Exceeded timeout.
# Clear interrupt.
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF)
timed_out = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, returning None is fine with me. I believe we do want an exception for send failure above though.

@jerryneedell
Copy link
Contributor Author

I think, hope, I got them all. Let me know if I missed something.
Thanks for the thorough review.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for these improvements @jerryneedell !

@jerryneedell
Copy link
Contributor Author

Thanks for finding/fixing the typos :-(

@tannewt tannewt merged commit 10f68ef into adafruit:master May 8, 2018
@jerryneedell jerryneedell deleted the jerryn_power branch May 9, 2018 10:06
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants