1

I’m working on interfacing a ZTW523A touch controller with an ESP32 via I2C, but I’m facing issues with I2C timeouts (Wire.h error 5: timeout) and I am unable to detect the device using an I2C scanner. Despite following the recommended setup and adding pull-up resistors, the bus doesn’t seem to communicate with the touch controller.

#include <Wire.h>
#include <Arduino.h>
#include <I2CScanner.h>

#define RESET_PIN D7
#define SCL_PIN D5 // ESP32 GPIO connected to Reset (pin 24)

I2CScanner scanner;

void resetTouchPanel()
{
  pinMode(RESET_PIN, OUTPUT);
  digitalWrite(RESET_PIN, LOW); // Pull Reset low
  delay(5);                      // Hold for 5ms
  digitalWrite(RESET_PIN, HIGH); // Release Reset

  delay(1000); // Wait for initialization
  Serial.println("Touch panel reset complete.");
}

void resetI2CBus()
{
  pinMode(SCL_PIN, OUTPUT);
  for (int i = 0; i < 9; i++)
  { // Generate clock pulses
    digitalWrite(SCL_PIN, HIGH);
    delayMicroseconds(10);
    digitalWrite(SCL_PIN, LOW);
    delayMicroseconds(10);
  }
  pinMode(SCL_PIN, INPUT); // Restore SCL to input
}
void setup()
{
  Serial.begin(115200);
  delay(100);

  resetTouchPanel();

  Wire.end();

  Wire.begin();
  Wire.setClock(100000);
  delay(100);
  resetI2CBus();
  scanner.Init();
}

void loop()
{
  delay(10);

  resetTouchPanel();
  scanner.Scan();
}
  • Added 2.2kΩ pull-up resistors to SDA and SCL lines (also tried 4.7kΩ).
  • Tried lowering the I2C clock speed to 50kHz and 100kHz.
  • Ensured the ZTW523A is properly reset (RESETn held low for 1ms, then released, with a 100ms wait before communication).
  • Ran the I2C scanner with no devices detected.
  • Tested the ESP32 I2C bus with another I2C device (successful detection, confirming the bus works).

Could this be an issue with the ZTW523A initialization sequence or reset behavior? Is there a specific I2C address or configuration I might be missing? Are there additional debugging techniques (e.g. logic analyzer) I should try?

Can someone help me debug this issue? Thank you so much!

2
  • 3
    If the ESP32 is the I2C master then surely the clock signal should always be an output from the ESP32. You configure it as an input. Commented Nov 29, 2024 at 16:44
  • Thank you for your suggestion. In the code, the SCL pin is indeed set to input. But even disabling (commenting out resetI2CBus()) this does not help in this case. Do you have any further suggestions for me? Thank you very much!! Commented Dec 2, 2024 at 11:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.