This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PZ: XPT2046 interfacing

Part Number: TM4C123GH6PZ

Hi, I am trying to interface the TFT touch screen, I am able to interface the LCD controller but having trouble in interfacing the touch controller, 

Details of the Controllers:

Microcontroller : TM4C123GH6PZ

Touch screen Controller : XPT2046 (Resistive, 4 wire)

the TFT I'm using is Waveshare's 3.5 inch 320x480 Touch Shield.

anyone having the solution then please share.

Thank you.

  • Alam said:
    I am able to interface the LCD controller but having trouble in interfacing the touch controller

    Feel your pain - yet "having trouble" is near kin to,  "Does NOT Work" - which provides (very) little detail - to enable effective assistance.

    Your touch controller is designed to regularly  scan your display's touch screen - and report  (both) the occurrence & location of  "touch."     

    Thus - "having trouble" may include:

    • no indication (via interrupt, usually) of  touch occurrence
    • no or only single axis - touch location reported
    • both touch axes report - yet coordinates are in error

    The  "vagueness" of  "having trouble" - forces we helpers to consider  "Each/Every" possibility - that's not fair - is it?

    As a general troubleshooting guide for touch controllers:

    • have you (recently) and (really) - confirmed that the touch controller is properly powered?
    • have you (r & r, as above) - confirmed that your interface connections - between MCU & Touch Controller are correct?
    • have you confirmed that your MCU is properly generating any required "Command-Control" Signals - required by the Touch Controller?
    • have you "touched and/or probed" the Touch Screen - while scoping the touch controller's output signals - to insure that they become active?

    I've not made the (added) effort to "recover & read" your touch controller's spec.     A link - (usually poster provided) -  "speeds/eases" - the efforts of  your helpers.

  • Read again - I'm "In the Air" - service is "spotty."
  • "both touch axes report - yet coordinates are in error"
    I'm getting wrong coordinates, when compared with the calculations provided by the vendor.

    "have you (recently) and (really) - confirmed that the touch controller is properly powered?"
    yes the controller is properly powered.

    "have you (r & r, as above) - confirmed that your interface connections - between MCU & Touch Controller are correct?"
    yes there is no miss communication between MCU and Touch controller.

    "have you confirmed that your MCU is properly generating any required "Command-Control" Signals - required by the Touch Controller?"
    yes it is generating proper command signals.

    have you "touched and/or probed" the Touch Screen - while scoping the touch controller's output signals - to insure that they "become active?"
    This part I have to check now.
    thanks for the suggestion.

    here's the touch controller's link, for your reference
    www.buydisplay.com/.../XPT2046.pdf
  • Might your "Attention to Detail" NOW - be especially noted?       And your situation is SO MUCH clearer - is that not so?     What a difference between (this) and your opening post - don't you agree?    VERY good job!
    We are "above the traffic" - yet small craft are buffeted - weather  "not so hot."

    Here's a STAB - "Might  your understanding of - and/or that of the touch controller" - "BE OFF BY 90°"?    (such that X is really Y & vice-versa...)     That's "in the realm" - is it not?    (and (pardon) why (some) get the big bucks)       Doubt I can read the spec prior to landing ... 2+ hours...    Again - good job!

  • We've smoothed out now - and suddenly -  I'm really tired.      (major prep-work prior to this trip)

    Dawns that the controller may be providing an "unusual and/or unexpected" output format.     (two's complement,  perhaps - you must check)
    It proves (always wise) to, "Touch/Probe at EACH of the Screens (near) Corners - and Log those Results."     Such proves an excellent "Sanity Check" - just in case the vendor (or you) have "misinterpreted "X/Y" and/or  "Screen MIN vs MAX."

    Do advise if you (still) need me to read your spec...     (cb1 Out)

  • Half of this thread has gone silent - half continues.      Having had the chance to review the spec - this Touch Screen Controller is (very) near the top - if not the MOST COMPLEX,  Resistive Touch Controller I've encountered.     I'd judge this one as demanding (unblinking)  "Attention to Detail" - nothing less.      And possibly - not the best choice for an "early or first" project.

    This Controller promises - beyond returning 12 bit, "touch coordinates" from each axis - to (additionally) provide measures of: Temperature, System Low Voltage, and (even) Touch Pressure!     (I'm bit doubtful on the latter)     In this user's case - those "extra features" come with a cost - that being added complexity.

    For the poster - and those following (if any) here's the Touch Controller's Timing Chart.     (those neat "Green Timing extender lines" -  (artfully) added by moi)

    Now:  "CS, DCLK & DIN" are MCU Outputs - "Busy & DOUT" are  MCU Inputs.      To ease poster (or reader) stress - it is likely that:  "DCLK & DIN"  translate to "SPI_CLK & MOSI."    And  "DOUTtranslates to "MISO."    CS - due to its LONG Period (24 clocks) must be managed via a simple GPIO - not part of the SPI Pin "Constellation!"      (watch that word arrive here (uncredited) - shortly...)

    As the Touch Controller's Timing Diagram reveals - an "SPI Format" must be chosen which: "Clocks Data Out of the MCU on clock's rising edge" - while "Clocking Data In to the MCU on that clock's falling edge."     [edit] that  falling edge (clocking in Touch data) ... (may) be true - on Mars!    I now believe that the SPI clock's Rising Edge - works to clock data BOTH OUT as well as IN.    In my defense - there is a "wasted clock" (clock #9) which I now suspect must be detected & ignored - and the 10th clock's Rising Edge - starts the "Clocking in of Touch Data!       (it remains unknown - if the thread's originator made that connection - and then succeeded in its implementation.)

    One page earlier - w/in the XPT Controller's data manual - the "Command/Control" Word (first 8 bits) is detailed - defining ALL.     Again - great flexibility & capability (may) result - if the required complexity is satisfied.    (maybe)

    I earlier questioned the "Touch Controller's" Data Output format - it is "Straight Binary" - although no attempt was made to "link" the "Min/Max" Touch Values - to any particular: L-R-T-B  (i.e. left-right-top etc.) side of the attached Touch Screen.     That exercise (or discovery) left to the user/observer...

  • Thank you for the suggestion, this helped me a lot, finally made it work. One more thing, we have to send a dummy write before reading the Y-coordinate value and a write with (1000) for 16-bit SPI configuration and (01) for 8-bit LSB first, this makes the touch interrupt active. Make sure to write this before you start reading the X and Y coordinates, if you don't write "1" before the Data command the next bits will not be considered as valid by the XPT2046 controller. Hope it helps anyone whos having problem.

    Thank you for your advise and suggestions.
  • Congratulations to you - my friend -  your "Special Efforts & Persistence" - prove  MOST IMPRESSIVE!     And thank you for making the (extra) time/effort - to update us - and your kind, "this Resolved!

    Even after being (somewhat) in that business - the complexity of your specific Touch Screen Controller - exceeds (most any) my team has "used or noted."

    You may consider, "Prompting the User to "Touch various (diagonally opposite) Screen Targets" - which will insure the Touch Controller's (proper calibration) - upon Power-Up.    (that insurance provided - ONLY - w/the extra programming effort - I am (now) "forcing upon you.")

    You may note too - that with "Age" - most resistive Touch Screens will undergo resistance "shifts" - thus regular "Calibration" - (may) make sense.    

    And one more (unexpected) issue - should your Display's backlight be often on - and at high power - the Touch Screen's resistance will likely change - and the "Calibration Genie" - must be (again) ... summoned! ... (Strong chain - attaching he/she to the Screen - usually  speeds/eases...)

  • Thank you, will keep that in mind.
  • Re: "Will keep that in mind." Staff does too - awards my suggestions w/their *usual" (not too disguised) eye rolls.

    They DO - (this time)  make a good point ... as you have "committed" to that Touch Screen Controller (due to your significant investment of time/effort) - and  "Staff senses that it is not a "BIG RUNNER"  - you may do well to inquire about "Securing MORE" - so that you can "best exploit" your fine learning!      (even advantaged components - fairly often - do not persist/survive!)

    It  always proves a great advantage to, "Re-Use" a past design - yet such "re-use" - demands the availability of that (past) device...