TTGO Lora32 V2 with 2 SPI
This is a very well made board, but as most of the boards from china, the document is always a pain...
This board has Lora and SD slot, both are on different SPI...yes, esp32 has 2 SPIs.
But arduino has SPI for one, the pins are defined in the HAL, so most libraries in arduino use the only one SPI.
TTGO lora32 has SPI pins:
MISO MOSI SCK CS
SD IO02 IO15 IO14 IO13
Lora IO19 IO27 IO05 IO18
According to:https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_master.html
there are 4 SPIs on esp32, SPI0 and SPI1 are used for internal flash.
HSPI/VSPI has 3 CS line each, to drive 3 devices each.
TTGO does provide a lora example:https://github.com/LilyGO/TTGO-LORA32-V2.0
but TTGO does not provide the example on SD for LoraV2 board. but here: https://github.com/LilyGO/TTGO-SD-test/blob/master/ESP32__goodSD/ESP32__goodSD.ino
There is an example from Espressif about using 2SPI, HSPI/VSPI
https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino
In the gihub of TTGO lora 32 V2, there is an closed issue using redefined SPI:
Combine the above 2 source, I tested with following, and it shows no error:
Once you remove the SD card, it seems fine. My guess is that Pin IO02 is used for internal flash writing....(according to what I found in internet)
I have also test it: first send data then write into sdcard, it works just fine.
This board has Lora and SD slot, both are on different SPI...yes, esp32 has 2 SPIs.
But arduino has SPI for one, the pins are defined in the HAL, so most libraries in arduino use the only one SPI.
TTGO lora32 has SPI pins:
MISO MOSI SCK CS
SD IO02 IO15 IO14 IO13
Lora IO19 IO27 IO05 IO18
According to:https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_master.html
there are 4 SPIs on esp32, SPI0 and SPI1 are used for internal flash.
HSPI/VSPI has 3 CS line each, to drive 3 devices each.
TTGO does provide a lora example:https://github.com/LilyGO/TTGO-LORA32-V2.0
but TTGO does not provide the example on SD for LoraV2 board. but here: https://github.com/LilyGO/TTGO-SD-test/blob/master/ESP32__goodSD/ESP32__goodSD.ino
There is an example from Espressif about using 2SPI, HSPI/VSPI
https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino
In the gihub of TTGO lora 32 V2, there is an closed issue using redefined SPI:
#include "FS.h"
#include "SD.h"
#include "SPI.h"
SPIClass spiSD(HSPI);
#define SD_CS 13
#define SDSPEED 27000000
void setup(){
Serial.begin(115200);
spiSD.begin(14,2,15,13);//SCK,MISO,MOSI,ss // инициализируем HSPI1
if(!SD.begin( SD_CS, spiSD, SDSPEED)){
// if(!SD.begin()){
Serial.println("Card Mount Failed");
return;
}
Combine the above 2 source, I tested with following, and it shows no error:
#include "FS.h"But when uploading the code, if I keep the sd card in the slot, it has a good chance that the code does not upload. and arduino IDE shows can't connect to esp32.
#include "SD.h"
#include "SPI.h"
#include <LoRa.h>
SPIClass spiSD(HSPI);
#define SD_CS 13
#define SDSPEED 27000000
SPIClass spiLora(VSPI);
#define SCK 5 // GPIO5 -- SX1278's SCK
#define MISO 19 // GPIO19 -- SX1278's MISnO
#define MOSI 27 // GPIO27 -- SX1278's MOSI
#define SS 18 // GPIO18 -- SX1278's CS
#define RST 14 // GPIO14 -- SX1278's RESET
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
#define BAND 915E6
void setup() {
Serial.begin(115200);
//-------SD---------------------------
spiSD.begin(14, 2, 15, 13); //SCK,MISO,MOSI,ss // инициализируем HSPI1
if (!SD.begin( SD_CS, spiSD, SDSPEED)) {
// if(!SD.begin()){
Serial.println("Card Mount Failed");
return;
}
//------------lora-----------------------
spiLora.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
//LoRa.onReceive(cbk);
// LoRa.receive();
Serial.println(" lora init ok");
}// end of setup
void loop() {
}
Once you remove the SD card, it seems fine. My guess is that Pin IO02 is used for internal flash writing....(according to what I found in internet)
I have also test it: first send data then write into sdcard, it works just fine.
留言
張貼留言