-
I tried many things but none work. Documentation: SPIClass spi(VSPI);
SPISettings spiSettings(2000000, MSBFIRST, SPI_MODE0);
SX1262 radio = new Module(cs, irq, rst, gpio, spi, spiSettings);
void setup() {
spi.begin();
(...)
radio.begin();
} I want to use the normal SPI, and keep normal SPI settings. I can leave the spiSettings field empty for it to default to My code is #include <RadioLib.h>
#include <SPI.h>
#define LORA_CS 14
#define LORA_SCK 21
#define LORA_MOSI 38
#define LORA_MISO 39
#define LORA_RESET 40
#define LORA_BUSY 41
#define LORA_DIO1 42
SPI.setPins???(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_SS); // I don't know what to put here
SX1262 radio = new Module(LORA_CS, LORA_DIO1, LORA_RESET, LORA_BUSY);
void setup() {
Serial.begin(115200);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 46 replies
-
Bad news, that's the Arduino default, but you could just blank the V out of your mind and you get SPI. These should help: https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/spi.html |
Beta Was this translation helpful? Give feedback.
-
#include <RadioLib.h>
#include <SPI.h>
#define LORA_CS 14
#define LORA_SCK 21
#define LORA_MOSI 38
#define LORA_MISO 39
#define LORA_RESET 40
#define LORA_BUSY 41
#define LORA_DIO1 42
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define VSPI FSPI
#endif
//SPI.setPins???(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_SS);
// uninitalised pointers to SPI objects
SPIClass * vspi = NULL; // What does this do? Is it needed?
SX1262 radio = new Module(LORA_CS, LORA_DIO1, LORA_RESET, LORA_BUSY, vspi);
void setup() {
Serial.begin(115200);
vspi = new SPIClass(VSPI);
vspi->begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
|
Beta Was this translation helpful? Give feedback.
-
#include <RadioLib.h>
#include <SPI.h>
#define LORA_CS 14
#define LORA_SCK 21
#define LORA_MOSI 38
#define LORA_MISO 39
#define LORA_RESET 40
#define LORA_BUSY 41
#define LORA_DIO1 42
SPIClass spi(SPI);
SX1262 radio = new Module(LORA_CS, LORA_DIO1, LORA_RESET, LORA_BUSY, spi);
void setup() {
Serial.begin(115200);
spi.begin();
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
} This compiles, but there is nowhere to specify the SPI pins. |
Beta Was this translation helpful? Give feedback.
-
@S5NC I suggest slowing down a bit. How did you arrive at the conclusion that the SPI is broken? What is the error code? What is the debug output? If the only error you have seen so far is -707 then that can very well mean the SPI is working and you just have incorrect crystal (as the Troubleshooting guide shows. Start by observing the symptoms before taking wild guesses ... |
Beta Was this translation helpful? Give feedback.
-
Can you put your 8 layer PCB design up on to your Git repro just in case there is something up with the routing. |
Beta Was this translation helpful? Give feedback.
-
Here is the working code which I am using to set custom SPI pins on the ESP32-S3 and SX1262: #include <RadioLib.h>
#include <SPI.h>
#define SX1262_CS 14
#define SX1262_SCK 21
#define SX1262_MOSI 38
#define SX1262_MISO 39
#define SX1262_RESET 40
#define SX1262_BUSY 41
#define SX1262_DIO1 42
#define SX1262_DIO2_AS_RF_SWITCH 1
#define SX1262_TXEN RADIOLIB_NC
#define SX1262_RXEN 10
SX1262 radio = new Module(SX1262_CS, SX1262_DIO1, SX1262_RESET, SX1262_BUSY);
void checkState(int16_t state) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("[SX1262] configuration failed with code "));
Serial.println(state);
while (true) {}
}
}
void setup() {
Serial.begin(115200);
SPI.begin(SX1262_SCK, SX1262_MISO, SX1262_MOSI, SX1262_CS);
Serial.printf("SPI.begin(SCK=%d, MISO=%d, MOSI=%d, CS=%d)\n", SX1262_SCK, SX1262_MISO, SX1262_MOSI, SX1262_CS);
SPI.setFrequency(4000000);
Serial.println(F("[SX1262] Initialising ... "));
checkState(radio.begin(868.0, 250.0, 11, 5, 0x2B, 8, 16, 1.8, false));
checkState(radio.setFrequency(869.525, false)); // you can remove this line and just put 869.525 instead of 868.0 in the line above once a release with the calibration range has been released.
checkState(radio.setCurrentLimit(140));
checkState(radio.setCRC(true));
checkState(radio.setDio2AsRfSwitch(SX1262_DIO2_AS_RF_SWITCH));
radio.setRfSwitchPins(SX1262_RXEN, SX1262_TXEN); // void
checkState(radio.setRxBoostedGainMode(true));
Serial.println(F("[SX1262] All settings succesfully changed!"));
}
void loop() {} |
Beta Was this translation helpful? Give feedback.
Here is the working code which I am using to set custom SPI pins on the ESP32-S3 and SX1262: