-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conversation
… from FIFO - reduce _BUFFER - only needed for register access - cleanup rececive
There was a problem hiding this 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.
adafruit_rfm9x.py
Outdated
timed_out = False | ||
while not timed_out and not self.tx_done: | ||
if (time.monotonic() - start) >= timeout_s: | ||
timed_out = True |
There was a problem hiding this comment.
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.
adafruit_rfm9x.py
Outdated
@@ -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.): |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
adafruit_rfm9x.py
Outdated
return None # Exceeded timeout. | ||
# Clear interrupt. | ||
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF) | ||
timed_out = True |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
adafruit_rfm9x.py
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typos
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :-)
There was a problem hiding this 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.
adafruit_rfm9x.py
Outdated
@@ -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. |
There was a problem hiding this comment.
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. :-)
adafruit_rfm9x.py
Outdated
return None # Exceeded timeout. | ||
# Clear interrupt. | ||
self._write_u8(_RH_RF95_REG_12_IRQ_FLAGS, 0xFF) | ||
timed_out = True |
There was a problem hiding this comment.
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.
I think, hope, I got them all. Let me know if I missed something. |
There was a problem hiding this 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 !
Thanks for finding/fixing the typos :-( |
Updating https://github.com/adafruit/Adafruit_CircuitPython_RFM9x to 1.0.3 from 1.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_RFM9x#4 from jerryneedell/jerryn_power
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.