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.