This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to send/receive Lora data

Dear Community;

I am trying to send some data via Lora with a nRF9160 connected with SPI to RF95W Lora module. The transmitter is a nRF9160 with a RF95W, and the receiver is a Raspberry Pi, also with a RF95W.

My transmitter code for nRF9160 is the one located in /zephyr/samples/drivers/lora/send:

/*
 * Copyright (c) 2019 Manivannan Sadhasivam
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

#define DEFAULT_RADIO_NODE DT_ALIAS(lora0)
BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay),"No default LoRa radio specified in DT");
#define DEFAULT_RADIO DT_LABEL(DEFAULT_RADIO_NODE)

#define MAX_DATA_LEN 10

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

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

void main(void)
{
	printk("\nStarting...\n");
	const struct device *lora_dev;
	struct lora_modem_config config;
	int ret;

	lora_dev = device_get_binding(DEFAULT_RADIO);
	if (!lora_dev) {
		printk("%s Device not found", DEFAULT_RADIO);
		return;
	}

	//config.frequency = 865100000;
	config.frequency = 868000000;
	config.bandwidth = BW_125_KHZ;
	config.datarate = SF_10;
	config.preamble_len = 8;
	config.coding_rate = CR_4_8;
	config.tx_power = 17;
	config.tx = true;

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

	while (1) {

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

		printk("\nData sent!");

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

this is the .overlay file:

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

&uart0 {
    current-speed = <115200>;
    status = "okay";
    tx-pin = <23>;
    rx-pin = <24>;
};

&uart1 {
    status = "disabled";
};


&spi3 {
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <20>;
mosi-pin = <21>;
miso-pin = <22>;
cs-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;

lora: sx1276@0 {
	compatible = "semtech,sx1276";
	reg = <0>;
	label = "sx1276";
	reset-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
	dio-gpios = <&gpio0 1 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
		<&gpio0 2 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
		<&gpio0 3 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
		<&gpio0 4 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
		<&gpio0 5 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
	spi-max-frequency = <1000000>;
	power-amplifier-output = "pa-boost";		
};
};

The connection between nRF and RF95W is the following:

3V --> 3V

GND --> GND

MOSI --> MOSI

MISO --> MISO

SCK --> SCK

GPIO 19 --> NSS(Chip select)

Then, I have an antenna connected to RF95W antenna pin.

Firts thing I don´t understand is regarding to this piece of code:

	lora_dev = device_get_binding(DEFAULT_RADIO);
	if (!lora_dev) {
		printk("%s Device not found", DEFAULT_RADIO);
		return;
	}

The program never enters in that if statement, also with the RF95W module completely disconnected... Also with the RF95W completely disconnected, I don´t get any error at lora_config() or lora_send() functions.

I only thing I have noticed is that if I have the RF95W and nRF9160 well conneted I see this information:

I: SX1276 Version:12 found

If I disconnect NSS(Chip select) I get:

I: SX1276 Version:ff found

If I disconnect 3V I get:

I: SX1276 Version:00 found

However, as mentioned before, I don´t get any errors in the program and I get "Data Sent!" print.

I also know that the Raspberry + RF95W receiver works fine, because we have been able to transmit data to it from another Raspberry + RF95W from 1km distance.

It is very important to us making RF95W work, and we don´t know that else we can try, best regards.

  • Hi,

    Are you using the nRF9160-DK to interface with the sx12xx module, or a custom module/board?

      

    Your DTS has a gpio conflict between RESET pin and DIO.

    	reset-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
    	dio-gpios = <&gpio0 1 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 2 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 3 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 4 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 5 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
    	spi-max-frequency = <1000000>;

     

    Please also note that there's a conflict with P0.01 as well, as this is normally configured as uart1 txd on the nrf9160dk atleast.

    You'll need to either choose another available GPIO, or disable the uart1 peripheral:

    &uart1 {
    	status = "disabled";
    };

     

    Kind regards,

    Håkon

  • Hi;

    I am using the Actinius Icarus board to interface the Lora module.

    I have changed the gpio you suggested, and uart1 was already disabled:

    This is my new actinius_icarus_ns.overlay file:

    / {
    	aliases {
    		lora0 = &lora;
    	};
    };
    
    &uart0 {
        current-speed = <115200>;
        status = "okay";
        tx-pin = <23>;
        rx-pin = <24>;
    };
    
    &uart1 {
        status = "disabled";
    };
    
    
    &spi3 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    sck-pin = <20>;
    mosi-pin = <21>;
    miso-pin = <22>;
    cs-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;
    
    lora: sx1276@0 {
    	compatible = "semtech,sx1276";
    	reg = <0>;
    	label = "sx1276";
    	reset-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
    	dio-gpios = <&gpio0 31 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 2 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 3 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 4 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
    		<&gpio0 5 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
    	spi-max-frequency = <1000000>;
    	power-amplifier-output = "pa-boost";		
    };
    };

    I see same behavoiur as previous tests, if the Lora module is disconnected I don´t see any error and there is no way to send anything. If you think it can be useful, we have some nRF9160 DK at the office, so I think I could try there.

    Thank you for your help.

    Best regards.

  • Hi;

    I have also tried to build for a nRF9160 DK. I can build the project without problems. However, I have the same problem, I don´t get any errors in the program with the Lora module disconnected...

    Could you try to build the project to see if same happens with your nRF9160 DK?

    Best regards.

  • Hi,

     

    I do not have such a module to connect to.

    The nRF9160-DK has certain pins that are dedicated to other operations, like UART/buttons/LEDs, which means that not all GPIOs are routed to the pin-headers.

    Please see the nrf9160-dk userguide for more info: https://infocenter.nordicsemi.com/topic/ug_nrf91_dk/UG/nrf91_DK/board_controller.html?cp=2_0_5_4_6_0

     

    If you flip the nRF9160-DK, there's a brief explanation on how the pins are routed as well.

     

    Note that when doing changes to the DTS, always delete your build folder and re-generate your project to ensure that the changes are taken into effect.

    Also try to probe you lines to see the communication between the nRF and the module.

     

    Kind regards,

    Håkon

  • Hi;

    I imagined that you will not have SX1276 Lora module, but could you find please why this piece of code is not working? Or why I don't get errors at lora_config or lora_send functions?

    	if (!lora_dev) {
    		printk("%s Device not found", DEFAULT_RADIO);
    		return;
    	}

    For that the Lora module if not necessary.

    Meanwhile, I will try to see SPI communication between the Lora module and nRF9160. 

Related