Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

change init to be consistent with set_lora_modem() doc #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

taotien
Copy link

@taotien taotien commented Jun 13, 2023

I've been trying to get the Adafruit LoRa Radio RFM95W to work for a while, and found this bit to be inconsistent with the documentation in the sx1276_7_8_9, and was what prevented the radio from working

@taotien taotien changed the title change to be consistent with set_lora_modem() doc change init to be consistent with set_lora_modem() doc Jun 13, 2023
@ceekdee
Copy link
Collaborator

ceekdee commented Jun 13, 2023

  • For the sx1276/7/8/9, the RadioKind reset() sets the Semtech chip in sleep mode to ensure that henceforth it is configured as a LoRa radio. All settings of state after that ensure LoRa mode is maintained:

impl LoRaMode {
/// Mode value, including LoRa flag
pub fn value(self) -> u8 {
(self as u8) | 0x80u8
}
}

  • self.ensure_ready(RadioMode::Sleep).await?; does nothing for the sx1276/7/8/9 RadioKind;

  • changing the API init() function affects all LoRa chips, not just the sx1276/7/8/9. Changes should be restricted to the RadioKind implementation.

It is not clear to me at this point that the current implementation is out of spec, nor why the RFM95W fails to initialize properly.

If it needs to be pushed into sleep twice to be properly initialized, consider a change to the sx1276/7/8/9 radio kind reset() function to do it there. Also, add a new board type for this board in mod_params.rs and only call the extra sleep() call for that board type.

@ceekdee ceekdee added the ?.?.x release Non-breaking bug/patch release label Jun 13, 2023
@taotien
Copy link
Author

taotien commented Jun 13, 2023

The problem was that set_suspend was called after the reset, but before the set_lora_modem. Perhaps set_sleep should be set inside set_lora_modem in the sx126X impl? I don't have other chips to test this on, only these feathers.

I forgot ensure_ready doesn't do anything, although the init routine in the RadioHead Arduino library I based this change on does call a register read to check if sleep was properly entered.

    // Set sleep mode, so we can also set LORA mode:
    spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE);
    delay(10); // Wait for sleep mode to take over from say, CAD
    // Check we are in sleep mode, with LORA set
    if (spiRead(RH_RF95_REG_01_OP_MODE) != (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE))
    {
//	Serial.println(spiRead(RH_RF95_REG_01_OP_MODE), HEX);
	return false; // No device present?
    }

I'll add a board type once I figure out some of the other specifics, as I had to comment out set_oscillator to get it to work as well.

@ceekdee
Copy link
Collaborator

ceekdee commented Jun 13, 2023

Thank you for working through the specifics for the Feather boards. It will be great to get that into lora-phy. The initial implementation was tested on an stm32l0.

One additional thing to note for sx1276/7/8/9 is that timeout detection in single read mode does not work. To do that requires setting up an extra DIO pin to await IRQ interrupts. Since I can't be sure the extra pin will be available across all sx1276/7/8/9 boards, I am testing polling for symbol timeout instead, which I believe will be a better solution across all kinds of Semtech chips and will better support LoRaWAN read windowing. This will be part of a version 2 release, since it requires slight API changes to accommodate polling.

Read continuous mode, where timeout is determined by the calling layer, does work in version 1.

@ceekdee
Copy link
Collaborator

ceekdee commented Jun 17, 2023

As you run into additional issues with the Feather boards, I'd be glad to help brainstorm solutions here. I expect there will be unique properties across LoRa boards of a given kind, and hope that the architecture has enough flexibility to provide support. Where the architecture falls short, it will be enhanced.

Also, if you are interested, there is a group chat on LoRaWAN/LoRa for Rust, which often touches on lora-phy and LoRaWAN 1.0.4:

https://matrix.to/#/#public-lora-wan-rs:matrix.org

@ceekdee
Copy link
Collaborator

ceekdee commented Jun 26, 2023

Please address an updated PR to lora-phy v2.0.0.

Update on 2023/8/26:

It's fine to create an updated PR against the v1.x branch instead. The version 1 release will be maintained for a while.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
?.?.x release Non-breaking bug/patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants