-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ST7920 on 2nd ESP32 SPI BUS (HSPI) in HW mode #1331
Comments
In general 2ND HW is not supported for ESP (at least this was the case some time back). Line 862 in 1b656cb
Then replace SPI by any other object refering to your second HW SPI. |
Thank you for the hint. I will give it a try. |
So yesterday, I succeeded to make my ESP32 (ESP32 DEVKIT V1) drive my ST7920 (RepRap 12864 LCD) in HW SPI mode on the 2nd SPI BUS (HSPI on pins 12 13 14 & 15) following the advise of @cbpdk : #377 (comment) The advantage of this method is that it only touches the u8g2 files and leaves the ESP32 libraries intact. So to make it as clear as possible for the next one facing the problem, here is exactly what I did:
/* Declare a second SPI in case of ESP32 */
#if defined(ARDUINO_ARCH_ESP32)
#define SPI_INTERFACES_COUNT 2
#endif
/* Declare a second SPI in case of ESP32 */
#include "U8x8lib.h"
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
/* Declare a second SPI in case of ESP32 */
#if defined(ARDUINO_ARCH_ESP32)
#if SPI_INTERFACES_COUNT > 1
SPIClass SPI1(HSPI);
#endif
#endif With those 2 modifications, I could run the u8g2 GraphicsTest.ino a full night without any problem (note: the speed change in the setup() ): #include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
/* HSPI: ST7920 LCD driver in HW SPI mode */
/* LCD EXT1-9 : GND */
/* LCD EXT1-10: 5V */
#define HSPI_MOSI_PIN 13 // To EXP1-3 = LCDE = ST7920 5 RW(SID)
#define HSPI_MISO_PIN 12 //
#define HSPI_SCK_PIN 14 // To EXP1-5 = LCD4 = ST7920 6 E(SCK)
#define HSPI_CS_PIN 15 // To EXP1-4 = LCDRS = ST7920 4 RS(CS)
U8G2_ST7920_128X64_F_2ND_HW_SPI u8g2(U8G2_R0, /* CS=*/ HSPI_CS_PIN, /* reset=*/ U8X8_PIN_NONE); //needed before u8g2.begin() : u8g2.setBusClock(600000);
void setup(void) {
u8g2.setBusClock(600000); // Needed with the "RepRap 12864 LCD" (ST7920)
u8g2.begin();
}
void loop(void) {
// put your code here
delay(100);
} I hope this helps. When I have time, I will re-wire my ESP32 to verify that with this "patch" the fist SPI port can still be used and will report it here (so maybe @olikraus can include this in the library). |
Hi hilsonp ! |
I finally used another hardware for this project and can't do any tests right now. To reply to your question: Everything was made in Arduino IDE. |
I'm using:
My goal is to use this screen on the second SPI bus of the ESP32, in HW mode.
The ESP32 DEVKIT V1 with 30 GPIO pins used are the following:
SPI MOSI MISO CLK CS
VSPI GPIO 23 GPIO 19 GPIO 18 GPIO 5
HSPI GPIO 13 GPIO 12 GPIO 14 GPIO 15
To experiment this, I used the GraphicsTest.ino
My setup() is as follow:
void setup(void) { u8g2.setBusClock(600000); u8g2.begin(); }
Here are my tests (Markdown as messed up the comments around clock/data/reset):
// VSPI SW SPI => OK but slow
//U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=/ 18, / data=/ 23, / CS=/ 5, / reset=/ U8X8_PIN_NONE); // ESP32
// VSPI HW SPI => OK
//U8G2_ST7920_128X64_F_HW_SPI u8g2(U8G2_R0, / CS=/ 5, / reset=/ U8X8_PIN_NONE);
// HSPI SW SPI => OK but slow
//U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, / clock=/ 14, / data=/ 13, / CS=/ 15, / reset=/ U8X8_PIN_NONE); // ESP32
// HSPI HW SPI => NOK
U8G2_ST7920_128X64_F_2ND_HW_SPI u8g2(U8G2_R0, / CS=/ 15, / reset=*/ U8X8_PIN_NONE);
As you can see the 3 first combinations are working.
This let me conclude that:
Therefore, I'm raising my hand to get some help.
Is there anything I should change in the library sources to have U8G2_ST7920_128X64_F_2ND_HW_SPI working with my ESP32 ?
Notes: I have been reading plenty of tickets/forum pages before submitting this.
The text was updated successfully, but these errors were encountered: