Send sample with lora not working in custom board with nrf52832

Hello. I'm trying to run a sample with sending data via Lora. I'm using llcc68 but as I read in previous threads, the code for sx1262 should work on my chip.

Here is my code. I added a LED and a button to track if the device is flashed (I flash manually via nRF Connect for desktop).

#include <zephyr/device.h>
#include <zephyr/drivers/lora.h>
#include <errno.h>
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#define DEFAULT_RADIO_NODE DT_ALIAS(lora0)
BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DEFAULT_RADIO_NODE),
	     "No default LoRa radio specified in DT");

#define MAX_DATA_LEN 10

#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(lora_send);

char data[MAX_DATA_LEN] = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'};



#define POWER_GPIO_NODE DT_ALIAS(powergpio)
static const struct gpio_dt_spec power_gpio_spec = GPIO_DT_SPEC_GET(POWER_GPIO_NODE, gpios);

#define SW0_NODE DT_ALIAS(sw0)
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(SW0_NODE, gpios);

/* LED0_NODE is the devicetree node identifier for the node with alias "led0". */
#define LED0_NODE DT_ALIAS(led1)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

/* STEP 4 - Define the callback function */
void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	gpio_pin_toggle_dt(&led);
}
/* STEP 5 - Define a variable of type static struct gpio_callback */

static struct gpio_callback button_cb_data;


int main(void)
{

		int ret;


    ret = gpio_pin_configure_dt(&power_gpio_spec, GPIO_OUTPUT_ACTIVE);
    //gpio_pin_set_dt(&power_gpio_spec, 1);
	if (ret < 0) {
		return -1;
	}
    k_sleep(K_MSEC(1000));
		

	if (!device_is_ready(led.port)) {
		return -1;
	}

	if (!device_is_ready(button.port)) {
		return -1;
	}

	ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
	if (ret < 0) {
		return -1;
	}

	ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
	if (ret < 0) {
		return -1;
	}
	/* STEP 3 - Configure the interrupt on the button's pin */
	ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE);

	/* STEP 6 - Initialize the static struct gpio_callback variable   */
	gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));

	/* STEP 7 - Add the callback function by calling gpio_add_callback()   */
	gpio_add_callback(button.port, &button_cb_data);


	const struct device *const lora_dev = DEVICE_DT_GET(DEFAULT_RADIO_NODE);
	struct lora_modem_config config;
	

	if (!device_is_ready(lora_dev)) {
		LOG_ERR("%s Device not ready", lora_dev->name);
		return 0;
	}

	config.frequency = 865100000;
	config.bandwidth = BW_125_KHZ;
	config.datarate = SF_10;
	config.preamble_len = 8;
	config.coding_rate = CR_4_5;
	config.iq_inverted = false;
	config.public_network = false;
	config.tx_power = 4;
	config.tx = true;

	ret = lora_config(lora_dev, &config);
	if (ret < 0) {
		LOG_ERR("LoRa config failed");
		return 0;
	}

	while (1) {
		ret = lora_send(lora_dev, data, MAX_DATA_LEN);
		if (ret < 0) {
			LOG_ERR("LoRa send failed");
			return 0;
		}

		LOG_INF("Data sent!");

		/* Send data at 1s interval */
		k_sleep(K_MSEC(1000));
	}
	return 0;
}

Here is my overlay

&spi1 {
	compatible = "nordic,nrf-spi";
	status = "okay";
    cs-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
	pinctrl-0 = <&spi1_default>;
	pinctrl-1 = <&spi1_sleep>;
	pinctrl-names = "default", "sleep";

    lora0: sx1262@0 {
    compatible = "semtech,sx1262";
    status = "okay";
    reg = <0>;
    reset-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;
    busy-gpios = <&gpio0 20 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
    dio1-gpios = <&gpio0 7 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
    spi-max-frequency = <4000000>;
    };
};

/ {
    aliases {
            lora0 = &lora0;
    };
};

The project is building, I am flashing it, and the button with the LED works. The module manages to send something once if I press reset and that's it.

I am using NCS 2.8.0. Also I don't use dio1-gpios, it is just a dummy pin.

Has anyone encountered such problems? Please help.

Parents
  • Hi

    LORA is not really supported by Nordic in particular, and this is a Zephyr specific sample project, so we're not too familiar with it. I would say the first step here would be to enable some debugging in your config files to get some more logging information, as these error messages don't provide any error message or code that points to why the transmission fails.

    Then, if you can't get anywhere by debugging, please try asking in the Zephyr Discord channel for example which is a great place to get help or information on Zephyr related matters.

    Best regards,

    Simon

Reply
  • Hi

    LORA is not really supported by Nordic in particular, and this is a Zephyr specific sample project, so we're not too familiar with it. I would say the first step here would be to enable some debugging in your config files to get some more logging information, as these error messages don't provide any error message or code that points to why the transmission fails.

    Then, if you can't get anywhere by debugging, please try asking in the Zephyr Discord channel for example which is a great place to get help or information on Zephyr related matters.

    Best regards,

    Simon

Children
Related