this is using the library from StuartsProjects
not sure if it helps as there appears to be no way to specify the specific SPI port when there is choice, e.g. ESP32 VSPI and HSPI
this changes the default SPI port to use the ESP32 HSPI pins
// Heltec ESP32 LoRa SX1262 receiver text communication
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20
from https://github.com/StuartsProjects/SX12XX-LoRa
*******************************************************************************************************/
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
#include "SX1278_Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX127XLT LT; //create a library class instance called LT
// receive a packet
char RXBUFFER[RXBUFFER_SIZE]; //create the buffer that received packets are copied into
void loop() {
// wait for receive data
int RXPacketL = LT.receive((uint8_t *)RXBUFFER, RXBUFFER_SIZE, 60000, WAIT_RX); //wait for a packet to arrive with 60seconds (60000mS) timeout
if (RXPacketL != 0) { //if the LT.receive() function detects an error, RXpacketL is 0
Serial.print("Received OK ");
LT.printASCIIPacket((uint8_t *)RXBUFFER, RXPacketL); //print the packet as ASCII characters
int count = 0;
sscanf(RXBUFFER, "Hello World %d", &count); // get the packet counter for reply
transmitReply(count);
}
}
// transmit reply
char buff[50];
void transmitReply(int count) {
snprintf(buff, 50, "receive OK %d", count);
Serial.print(F("\nTransmit Packet> "));
LT.printASCIIPacket((uint8_t *)buff, strlen(buff)); //print the buffer (the sent packet) as ASCI //start transmit timer
if (LT.transmit((uint8_t *)buff, strlen(buff), 5000, TXpower, WAIT_TX)) //will return packet length sent if OK, otherwise 0 if transmit error
{
Serial.println(" Transmited OK!");
} else {
Serial.println(" transmit ERROR!"); //transmit packet returned 0, there was an error
}
delay(packet_delay); //have a delay between packets
}
void setup() {
Serial.begin(115200);
delay(3000);
Serial.println();
Serial.println(F("LoRa_Receiver_ESP32 Starting"));
Serial.println();
SPI.begin(SCK, MISO, MOSI, NSS);
if (LT.begin(NSS, NRESET, DIO0, LORA_DEVICE)) {
Serial.println(F("LoRa Device found"));
} else {
Serial.println(F("No LoRa device responding"));
while (1) delay(100);
}
LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
}
and the SX1278_Settings.h file (you would use the SX1280 header file)
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of the Tracker boards, the ESP32_Micro_Node, be sure to change
//them to match your own setup. You will also need to connect up the pins for the SPI bus, which on the
//ESP32_Micro_Node are SCK on pin 18, MISO on pin 19 and MOSI on pin 23.
// VSPI
//#define NSS 5 //select pin on LoRa device
//#define SCK 18 //SCK on SPI3
//#define MISO 19 //MISO on SPI3
//#define MOSI 23 //MOSI on SPI3
// HSPI
#define NSS 15 //select pin on LoRa device
#define SCK 14 //SCK on SPI3
#define MISO 12 //MISO on SPI3
#define MOSI 13 //MOSI on SPI3
#define NRESET 4 //reset pin on LoRa device
#define LED1 13 //on board LED, high for on
#define DIO0 2 //DIO0 pin on LoRa device, used for RX and TX done
#define VCCPOWER 16 //pin controls power to external devices
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
//******* Setup LoRa Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 866000000; //frequency of transmissions in hertz
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting, normally set to auto
const int8_t TXpower = 10; //LoRa transmit power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets
#define RXBUFFER_SIZE 32 //RX buffer size
when run the serial monitor displays that the LoRa module is found, e.g.
18:01:30.770 -> LoRa Device found
18:01:31.846 -> Received OK Hello World 1234567890*
18:01:31.846 -> Transmit Packet> receive OK 1234567890 Transmited OK!
18:01:33.964 -> Received OK Hello World 1234567890*
18:01:33.964 -> Transmit Packet> receive OK 1234567890 Transmited OK!
18:01:36.079 -> Received OK Hello World 1234567890*
18:01:36.079 -> Transmit Packet> receive OK 1234567890 Transmited OK!
18:01:38.227 -> Received OK Hello World 1234567890*
18:01:38.227 -> Transmit Packet> receive OK 1234567890 Transmited OK!
may have to edit the library files