Skip to content

Latest commit

 

History

History
110 lines (76 loc) · 4.59 KB

File metadata and controls

110 lines (76 loc) · 4.59 KB

🕵️‍♂️ Chapter 4: Troubleshooting and Reverse Engineering

You set up the system, uploaded the code, but only meaningless characters are flowing in the terminal... Or worse, nothing at all. Don't worry, 90% of UART problems stem from the 3 causes listed below.

In this chapter, we will learn how to make invisible signals visible.


4.1 The "Garbage Data" Problem 🧧

If you see meaningless symbols like `` or RW¥å in the terminal, it means communication exists but there is no agreement.

Possible Causes:

  1. Baud Rate Mismatch (Most Common):
    • If the transmitter sends at 9600 and the receiver listens at 115200, the data becomes garbage.
    • Solution: Check the device datasheet or measure the speed with a Logic Analyzer (See: 4.3).
  2. Missing GND (Ground):
    • If the grounds of the two devices are not connected, voltage levels "float". It becomes unclear whether a signal is 0 or 1.
    • Solution: Immediately connect the GND pins of both devices with a jumper wire.
  3. Faulty Crystal:
    • Cheap Arduino clones may have low-quality crystals, causing a frequency drift of more than 2%.

4.2 No Data (Silence) 🔇

If nothing is flowing on the screen, the situation is more serious. There might be a hardware disconnection.

Possible Causes:

  1. TX-RX Not Crossed:
    • Connecting TX -> TX and RX -> RX is the classic mistake. If two people talk at the same time, no one listens.
    • Solution: Reverse the cables and try again.
  2. Voltage Level Error (RS232 vs TTL):
    • If the sensor is RS232 (±12V) and you connected it directly to the ESP32 (3.3V), the ESP32 pin might be burnt.
  3. Bad Soldering / Contact:
    • Jumper wires on the breadboard can sometimes be broken internally. Perform a "Short Circuit Test" (Buzzer) with a multimeter.

4.3 Reverse Engineering: Solving the Unknown Device 🔓

You have a "black box" device with no documentation. Only 3 wires come out (TX, RX, GND). What is its speed? What is the protocol? To find this out, a $5 Logic Analyzer (Saleae Clone) is a lifesaver.

Step-by-Step Speed Detection (with Logic Analyzer)

  1. Connection: Connect the device's TX pin to CH1 of the Logic Analyzer, and GND to GND.
  2. Sampling: Open the Logic software (PulseView) and start recording at a high speed (e.g., 24 MHz).
  3. Measurement: Power cycle the device to force it to send data. You will see digital waves on the screen.
  4. Analysis:
    • Find the NARROWEST (shortest) pulse width. This is the duration of a single bit ($T_{bit}$).
    • Formula: $\text{Baud Rate} = \frac{1}{T_{bit}}$

Example: You measured the shortest pulse as 8.68 µs. $1 / 0.00000868 = 115,207$ Congratulations! The device speed is 115200 Baud.

graph TD
    subgraph SIGNAL [Signal Analysis]
    P1[Pulse Width: 104 µs] --> R1[1 / 0.000104 = 9615] --> C1{Result: 9600 Baud}
    P2[Pulse Width: 8.68 µs] --> R2[1 / 0.00000868 = 115207] --> C2{Result: 115200 Baud}
    end
    
    style C1 fill:#c8e6c9,stroke:#2e7d32
    style C2 fill:#c8e6c9,stroke:#2e7d32
Loading

4.4 USB-TTL Converter Traps ⚠️

The colorful USB converters (CP2102, CH340, FTDI) we use to connect from PC to ESP32 can sometimes be fake.

  • Fake FTDI Chips: Can become "bricked" (unusable) with a Windows update.
  • 3.3V / 5V Jumper: Some converters have a tiny jumper for voltage selection. Ensure this is in the 3.3V position for ESP32. If you supply 5V, you might burn the module.

✅ Serial Summary (Final Checklist)

You are now a UART master. Here is your final checklist before going into the field:

  1. Is GND Connected? (The most critical item)
  2. Is TX -> RX connected? (Cross connection)
  3. Are Voltage Levels Equal? (3.3V <-> 3.3V)
  4. Is Baud Rate the Same? (9600, 115200...)
  5. Is Cable Distance Appropriate? (Max 50cm for TTL, 1km for RS485)


Chapter 3: Integration Main Menu Support