为什么在调用外部功能后忽略了任何TFT-LCD命令?

发布于 2025-02-06 03:03:51 字数 1156 浏览 4 评论 0原文

我的项目是构建数据记录仪。我使用的是ESP32和2,8“ SPI TFT-LCD,带有ILI9341控制器和集成的SD卡插槽以及其他一些传感器。由于库和文档,我是Arduino IDE。如下所示。 启动SD卡之前,一切正常

在 代码只是用于测试目的,但相当很好地说明了问题:

//Included Libraries  
#include <SPI.h>  
#include <Adafruit_GFX.h>  
#include <Adafruit_ILI9341.h>  
#include <SD.h>

//used Pins on ESP32  
#define TFT_CS 15  
#define TFT_RST 0  
#define TFT_DC 2  
#define TFT_MOSI 23  
#define TFT_CLK 18  
#define TFT_MISO 19     

//initialize Library as "tft" with used Pins  
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);  

void setup() {
  
  Serial.begin(115200);  
  
  tft.begin();  
  tft.fillScreen(ILI9341_BLACK);  

  tft.drawCircle(100,100, 20, ILI9341_BLUE);  

  //at this point, a blue circle appears on the Display  

  //Start SD Card. If successfull draw red circle  
  
  if(SD.begin()){  

    tft.drawCircle(100,200, 20, ILI9341_RED);  
    
    Serial.print("red circle");
  
    //"red circle" appears in the serial monitor but no circle on the display, only a blue one   
  }  
}

void loop() {
}

如果我手动设置标志,则只有在调用外部功能时就可以使用。 。
提前致谢。

My project is to build a data logger. I'm using an ESP32 and a 2,8" SPI TFT-LCD with an ILI9341 controller and integrated SD-card slot along with some other sensors. I us the Arduino IDE because of the libraries and documentation. As seen in the code below, before starting the SD card everything works fine. However, after the SD card gets started (or any other function that originated from an included library gets called) any commands for the TFT simply get ignored. What is the reason for this?

The following code is just for testing purposes but illustrates the problem fairly well:

//Included Libraries  
#include <SPI.h>  
#include <Adafruit_GFX.h>  
#include <Adafruit_ILI9341.h>  
#include <SD.h>

//used Pins on ESP32  
#define TFT_CS 15  
#define TFT_RST 0  
#define TFT_DC 2  
#define TFT_MOSI 23  
#define TFT_CLK 18  
#define TFT_MISO 19     

//initialize Library as "tft" with used Pins  
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);  

void setup() {
  
  Serial.begin(115200);  
  
  tft.begin();  
  tft.fillScreen(ILI9341_BLACK);  

  tft.drawCircle(100,100, 20, ILI9341_BLUE);  

  //at this point, a blue circle appears on the Display  

  //Start SD Card. If successfull draw red circle  
  
  if(SD.begin()){  

    tft.drawCircle(100,200, 20, ILI9341_RED);  
    
    Serial.print("red circle");
  
    //"red circle" appears in the serial monitor but no circle on the display, only a blue one   
  }  
}

void loop() {
}

Funnily, if I set a flag manually it works fine. Only if extern functions are called (like SD.begin()) the commands get ignored.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤蝉 2025-02-13 03:03:51

如果可以的话,我会发表评论。我的怀疑是,您还使用ESP32用于SD卡的芯片选择的PIN(假设ESP32也将SPI用于SD卡)。 ESP可能会将其带出,因此,如果您不使用SD卡,则可以使用它。当然,我可能是错的,但是我的猜测仍然是这是两个设备之间一些硬件级干扰的结果。您可以链接您使用的特定ESP32板,以便我们看到正在使用哪些引脚?

编辑:感谢您提供的额外信息。我意识到您的问题可能是外部功能可能正在更改您已分配给TFT的某些引脚的PIN设置,例如,如果TFT_MOSI最初是将其配置为输出的,但是不同的功能将其配置为输入,然后与之通信LCD将不再起作用。也许尝试在SD.Begin()之后重新定位TFT对象,看看是否有效?

I would make this a comment if I could. My suspicion is that you are using the pin that the ESP32 uses for the SD card's chip select for the TFT as well (assuming the ESP32 uses SPI for the SD card too). The ESP probably brings that pin out so that you can use it if you aren't using the SD card. I could be wrong, of course, but my guess would still be that this is the result of some hardware-level interference between the two devices. Can you link the specific ESP32 board you're using so we can see what pins are being used?

Edit: Thanks for that extra info. I realized your problem might be that external functions might be changing the pin settings for some of the pins that you have allocated for the tft e.g. if TFT_MOSI is originally configured as an output, but a different function configures it as an input, then communicating with the LCD would no longer work. Maybe try reinitializing the tft object after that SD.begin() and see if that works?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文