View previous topic :: View next topic |
Author |
Message |
KansaiRobot
Joined: 25 Nov 2015 Posts: 5
|
XPT2046 Touch Controller |
Posted: Wed Nov 25, 2015 2:04 am |
|
|
Hello
I am trying to control a XPT2046 touch controller.
I have programmed it but it does not work.
I have come to the conclusion that the SPI part might be the culprit.
My first question would be at what speed do I have to set the SPI clock???
Thanks a lot for any advice or comment |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 25, 2015 2:29 am |
|
|
Post a link to the data sheet for the XPT2046 touch controller. |
|
|
KansaiRobot
Joined: 25 Nov 2015 Posts: 5
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 25, 2015 3:15 am |
|
|
Quote: | My first question would be at what speed do I have to set the SPI clock??? |
Look at pages 26 and 27 of the data sheet. DCLK high and low times are
200 ns minimum, which is a 400 ns period, and 2.5 MHz max. frequency. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Thu Nov 26, 2015 3:26 am |
|
|
Other obvious things are:
1) Remember Din on the chip = SDO on the PIC. Dout = SDI. It is very common to forget this swapping.
2) SPI mode number.
Looking at it the clock idles low. So CPOL=0, and data changes on the falling edge, so CPHA=0. SPI mode 1.
#USE SPI (SPI1, MODE=1, BAUD=2500000, STREAM=XPT)
Assuming you are using hardware SPI 1.
Drop CS - output_low(CS_PIN);
Clock out the 8bit command - spi_xfer(XPT, command,8);
Wait for 'BUSY' to go low. - while(INPUT(BUSY_PIN);
Read the 16bit reply - reply=spi_xfer(XPT,0,16);
Raise CS - output_high(CS_PIN);
Then reply/=16.
Obviously with suitable defined values for CS_PIN, BUSY_PIN, and value for 'command', and an int16 variable for 'reply'. |
|
|
KansaiRobot
Joined: 25 Nov 2015 Posts: 5
|
|
Posted: Thu Nov 26, 2015 6:25 pm |
|
|
I have written a program and I would appreciate some help
but it is written in XC compiler for PICs. Can I post it here?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
KansaiRobot
Joined: 25 Nov 2015 Posts: 5
|
|
Posted: Thu Nov 26, 2015 7:17 pm |
|
|
I see. Thank you for the indication.
Your explanation of the Frequency was very useful too. Very much grateful for that too |
|
|
|