Skip to content

Add reset parameter #22

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 1 commit into from
Jul 19, 2019
Merged

Add reset parameter #22

merged 1 commit into from
Jul 19, 2019

Conversation

brentru
Copy link
Member

@brentru brentru commented Jul 19, 2019

  • Resets the RFM9x module before attempting to read the RFM9x RegVersion. Prevents chip from starting/reading from a bad state.
  • Adds a deinit() method along with enter and exit methods for use with a context manager
  • Examples have been changed to reflect the addition of the RST pin.
  • Formatted file with Black

Tested on a Feather M4 with Radio FeatherWing.
Test Harness for setting up (and tearing down) the SPI interface and lora object:

import time
import busio
import digitalio
import board
from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa

# RFM9x Breakout Pinouts
cs = digitalio.DigitalInOut(board.D6) 
irq = digitalio.DigitalInOut(board.D5) 
rst = digitalio.DigitalInOut(board.D4)

# TTN Device Address, 4 Bytes, MSB
devaddr = bytearray([snip])

# TTN Network Key, 16 Bytes, MSB
nwkey = bytearray([snip])

# TTN Application Key, 16 Bytess, MSB
app = bytearray([snip])

ttn_config = TTN(devaddr, nwkey, app, country='US')

for i in range(0, 1001):
    print('init RFM9x and TinyLora...', i)
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    lora = TinyLoRa(spi, cs, irq, rst, ttn_config)
    print('Sending Packet...')
    data = bytearray(b"\x43\x57\x54\x46")
    lora.send_data(data, len(data), lora.frame_counter)
    print('Packet Sent!')
    print('tearing down TinyLoRa..')
    lora.deinit()
    print('tearing down SPI..')
    spi.deinit()

Test Output (snipped):

init RFM9x and TinyLora... 329
Sending Packet...
Packet Sent!
tearing down TinyLoRa..
tearing down SPI..
init RFM9x and TinyLora... 330
Sending Packet...

@brentru brentru requested a review from a team July 19, 2019 19:31
@brentru brentru merged commit 9f62cd6 into adafruit:master Jul 19, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 20, 2019
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