Hello,
I was using the send example which is located in C:\v1.5.1\zephyr\samples\drivers\lora and trying to send a message to an Arduino LoRa gateway.
However, I found out that nothing was got even though I could see "Data sent" in my terminal.
I thought it was a problem of nrf9160 because the gateway was able to receive the message sent by other device, which means that the nrf9160 didn't sent any message out.
The below was the code of the gateway.
#include <SPI.h> #include <LoRa.h> void setup() { Serial.begin(9600); while (!Serial); Serial.println("LoRa Receiver"); if (!LoRa.begin(868E6)) { Serial.println("Starting LoRa failed!"); while (1); } } void loop() { int packetSize=LoRa.parsePacket(); if (packetSize) { Serial.print("Received packet '"); while (LoRa.available()) { Serial.print((char)LoRa.read()); } Serial.print("' with RSSI="); Serial.print(LoRa.packetRssi()); Serial.print(" and SNR="); Serial.println(LoRa.packetSnr()); } }
I also found that someone had similar problems at devzone.nordicsemi.com/.../nrf9160-lora-spi and https://devzone.nordicsemi.com/f/nordic-q-a/74370/unable-to-send-receive-lora-data?pifragment-684=2 but still didn't help me solve the problem.
Here's the main.c file I modified from the send example
/* * 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("hello\n"); LOG_INF("hello"); const struct device *lora_dev; struct lora_modem_config config; int ret; lora_dev = device_get_binding(DEFAULT_RADIO); if (!lora_dev) { LOG_ERR("%s Device not found", DEFAULT_RADIO); return; } config.frequency = 868000000; config.bandwidth = BW_125_KHZ; config.datarate = SF_10; config.preamble_len = 8; config.coding_rate = CR_4_5; //from 4_5 to 4_8 config.tx_power = 4; //from 4 to 17 config.tx = true; ret = lora_config(lora_dev, &config); if (ret < 0) { LOG_ERR("LoRa config failed"); return; } while (1) { ret = lora_send(lora_dev, data, MAX_DATA_LEN); if (ret < 0) { LOG_ERR("LoRa send failed"); return; } LOG_INF("Data sent!"); /* Send data at 1s interval */ k_sleep(K_MSEC(3000)); } }
and here is my nrf9160dk_nrf9160ns.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"; dio-gpios = <&gpio0 13 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, <&gpio0 14 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, <&gpio0 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, <&gpio0 16 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>, <&gpio0 29 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; reset-gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; rfo-enable-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; spi-max-frequency = <1000000>; power-amplifier-output = "pa-boost"; //from rfo to pa-boost /* rfi-enable-gpios = <&gpio0 xx GPIO_ACTIVE_HIGH>; power-amplifier-output = "pa-boost"; pa-boost-enable-gpios = <&gpio0 xx GPIO_ACTIVE_HIGH>; antenna-enable-gpios = <&gpio0 xx GPIO_ACTIVE_HIGH>; tcxo-power-gpios = <&gpio0 xx GPIO_ACTIVE_HIGH>; tcxo-power-startup-delay-ms = <5>; */ }; };
And here is my prj.conf file
CONFIG_LOG=y CONFIG_SPI=y CONFIG_GPIO=y CONFIG_LORA=y CONFIG_LORA_SX12XX=y #CONFIG_LORA_SX127X=y #CONFIG_PRINTK=y CONFIG_SPI_3=y
Could anyone please help me with the problem?
Thanks a lot.