Skip to content
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

Pager receive example error for speed = 512 #665

Closed
brooksbUWO opened this issue Jan 17, 2023 · 3 comments
Closed

Pager receive example error for speed = 512 #665

brooksbUWO opened this issue Jan 17, 2023 · 3 comments
Labels
hw workaround Fix for a (suspected) hardware bug resolved Issue was resolved (e.g. bug fixed, or feature implemented)

Comments

@brooksbUWO
Copy link

In the pager receive example, pager.startReceive returns a status_code = -101 (RADIOLIB_ERR_INVALID_BIT_RATE) when using 512 for speed in pager.begin.

Is it possible to change

RADIOLIB_CHECK_RANGE(br, 1.2, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);

to RADIOLIB_CHECK_RANGE(br, 0.512, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);?



Just for reference, here's the code on the TTGO-LoRa32-V2.1 T3_V1.6.1.
#include <RadioLib.h>

// board = ttgo-lora32-v21
#define LORA_SCK        5
#define LORA_MISO       19
#define LORA_MOSI       27
#define LORA_SS         18
#define LORA_DIO0       26
#define LORA_DIO1       33
#define LORA_DIO2       32
#define LORA_RST        23

SX1276 radio = new Module(LORA_CS, LORA_IRQ, LORA_RST, LORA_DIO1);
PagerClient pager(&radio);
String pagerMsg = "";	  // Pager recieved data
int pagerAdr = 800828;    // Pager address


void setup() {
  Serial.begin(115200);

  // Initialize SX1276
  Serial.print(F("[SX1276] Initializing ... "));
  int state = radio.beginFSK();

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

  // Initalize Pager client
  Serial.print(F("[Pager] Initializing ... "));
  state = pager.begin(462.45, 512, true);	// 462.45 MHz, 512 bps, invert
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

  // start receiving POCSAG messages
  Serial.print(F("[Pager] Starting to listen ... "));
  state = pager.startReceive(LORA_DIO2, pagerAdr, 0);
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

}

void loop() {
  // the number of batches to wait for
  // 2 batches will usually be enough to fit short and medium messages
  if (pager.available() >= 2) {
    Serial.print(F("[Pager] Received pager data, decoding ... "));
    int state = pager.readData(pagerMsg);

    if (state == RADIOLIB_ERR_NONE) {
      Serial.println(F("success!"));

      // print the received data
      Serial.print(F("[Pager] Data:\t"));
      Serial.println(str);

    } else {
      // some error occurred
      Serial.print(F("failed, code "));
      Serial.println(state);

    }
  }
}
@jgromes
Copy link
Owner

jgromes commented Jan 17, 2023

The slowest data rate SX127x supports is 1200 bps, so no, this cannot be changed - it's a hardware limitation of the module.

@jgromes jgromes closed this as completed Jan 17, 2023
@jgromes jgromes added the question Generic question about code or usage label Jan 17, 2023
@brooksbUWO
Copy link
Author

brooksbUWO commented Jan 17, 2023

The slowest data rate SX127x supports is 1200 bps, so no, this cannot be changed - it's a hardware limitation of the module.

The datasheet only has a few examples of "Classical modem baud rates (multiples of 1.2kbps)" and it does not show 512 bps in their example. If we can set RegBitRateMsb=0xD0 and RegBitRateLsb=0x56, then 512 bps will work.

BitRateSettings

  // check allowed bit rate
  if(_ook) {
    RADIOLIB_CHECK_RANGE(br, 1.2, 32.768002, RADIOLIB_ERR_INVALID_BIT_RATE);      // Found that 32.768 is 32.768002
  } else {
    RADIOLIB_CHECK_RANGE(br, 0.512, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
  }

  // set mode to STANDBY
  int16_t state = setMode(RADIOLIB_SX127X_STANDBY);
  RADIOLIB_ASSERT(state);

  // set bit rate
  uint16_t bitRate = (RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / br;
  if (br = 0.512) {
    state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_MSB, 0xD0);
    state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_LSB, 0x56);
  } else {
    state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
    state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
  }

@jgromes
Copy link
Owner

jgromes commented Jan 18, 2023

There is a section in the datasheet that does actually specify the support bit rate range - in Table 7, minimum bit rate is 1.2 kbps.

However, I tested the 512 bps POCSAG and somewhat surprisingly, it does work and decodes in PDW. I usually use the parameter ranges from the datasheet, but in this case, it seems reasonable to make an exception. I lowered the minimum data rate for SX127x and RF69 (since it has the same FSK modem) to 500 bps, so now it should work without issues.

Thanks for pointing this out!

@jgromes jgromes closed this as completed Jan 18, 2023
@jgromes jgromes added resolved Issue was resolved (e.g. bug fixed, or feature implemented) hw workaround Fix for a (suspected) hardware bug and removed question Generic question about code or usage labels Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hw workaround Fix for a (suspected) hardware bug resolved Issue was resolved (e.g. bug fixed, or feature implemented)
Projects
None yet
Development

No branches or pull requests

2 participants