jgromes / RadioLib

Universal wireless communication library for embedded devices
https://jgromes.github.io/RadioLib/
MIT License
1.49k stars 376 forks source link

scanChannel without timeout in while, infinty loop. #24

Closed Sallatiel closed 5 years ago

Sallatiel commented 5 years ago

Hi, I am using arduino pro micro - atmega32u4 (INT0 and INT1 are pins exchanged in relation to arduino uno) and in scanChannel the code gets stuck in while waiting for an activity in INT0. In the comment says have timeout but do not have, should not have a timout? I am only with a radio and now I have no way to test if with channel activity it would pass this condition.

thank you! and congratulations to cubeSat

int16_t SX126x::scanChannel()
{
  // check active modem
  if (getPacketType() != SX126X_PACKET_TYPE_LORA)
  {
    return (ERR_WRONG_MODEM);
  }

  // set mode to standby
  int16_t state = standby();
  if (state != ERR_NONE)
  {
    return (state);
  }

  // set DIO pin mapping
  // state = setDioIrqParams(SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_CAD_DONE, SX126X_IRQ_CAD_DONE, SX126X_IRQ_CAD_DETECTED);
  // Use DIO1 only for both CAD DONE and CAD DETECTED interrupts
  state = setDioIrqParams(SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_CAD_DONE, SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_CAD_DONE);
  if (state != ERR_NONE)
  {
    return (state);
  }

  // clear interrupt flags
  state = clearIrqStatus();
  if (state != ERR_NONE)
  {
    return (state);
  }

  // set mode to CAD
  state = setCad();
  if (state != ERR_NONE)
  {
    return (state);
  }

  // wait for channel activity detected or timeout
  while (!digitalRead(_mod->getInt0()))
  {
    // No need to check DIO2
    // if(digitalRead(_mod->getInt1())) {
    //   clearIrqStatus();
    //   return(LORA_DETECTED);
    // }
  }

  // Get the CAD result
  uint16_t cadResult = getIrqStatus();
  if (cadResult == 0x8000)
  {
    clearIrqStatus();
    return (CHANNEL_FREE);
  }
  else // cadResult == 0x8001
  {
    clearIrqStatus();
    return (LORA_DETECTED);
  }
  return (CHANNEL_FREE);
}
jgromes commented 5 years ago

CAD timeout is controlled by the radio module itself, because CAD length depends on LoRa configuration. If you end up in an infinite loop it suggests incorrect wiring.

  1. What radio module are you using?
  2. Does it have TCXO? And if so, did you set the reference voltage?
  3. What's the wiring?

EDIT: Also, where did you get that code? It's not from the latest release of the library.

jgromes commented 5 years ago

Closed due to inactivity.

Sallatiel commented 5 years ago

Hello,

  1. EBYTE E22-900M22S;
  2. Yes, I saw that it has TCXO in DIO3 but I don't know what value to set in setTCXO;
  3. In Arduino Pro Micro (ATmega32u4): Sx1262 -------- Arduino Pro Micro (ATmega32u4) NSS ----------- 10 (PB6) SCK ----------- 15 (PB1) MOSI --------- 16 (PB2) MISO --------- 14 (PB3) BUSY ---------- 9 (PB5) DIO1 ---------- 3 (PD1 - INT0) DIO2 ---------- 2 (PD0 - INT1)
jgromes commented 5 years ago

If your module is using TCXO, you have to configure it by calling setTCXO(), otherwise it won't work. Apparently, 2.4 works with E22-900M22S (see https://github.com/jgromes/RadioLib/issues/12#issuecomment-497321332), but you should confirm that with the seller.

Sallatiel commented 5 years ago

Thanks!

working. I didn't find the crystal datasheet, is it a TCXO or VCTCXO? Is this pin on DIO3 crystal VDD or control? Thank you.

In most crystals I've seen, this pin 4 is VDD, 1 is VC if it's VCTCXO.

acd1c406-faaf-42f0-80bf-da4e2d8fda7e

jgromes commented 5 years ago

It's most likely a TCXO - see SX1262 datasheet, section 4.1.4. DIO3 provides the supply voltage from 1.6 to 3.3 V. Then again, I'm only guessing here - you should probably contact the seller or the manufacturer if you want more details.