CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

XPT2046 Touch Controller

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
KansaiRobot



Joined: 25 Nov 2015
Posts: 5

View user's profile Send private message

XPT2046 Touch Controller
PostPosted: Wed Nov 25, 2015 2:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 25, 2015 2:29 am     Reply with quote

Post a link to the data sheet for the XPT2046 touch controller.
KansaiRobot



Joined: 25 Nov 2015
Posts: 5

View user's profile Send private message

PostPosted: Wed Nov 25, 2015 2:37 am     Reply with quote

Thanks for the reply

the datasheet is at

http://www.waveshare.com/w/upload/9/98/XPT2046-EN.pdf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 25, 2015 3:15 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Thu Nov 26, 2015 3:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 26, 2015 6:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 26, 2015 6:48 pm     Reply with quote

No, this is the CCS compiler forum. If you're using XC8, then post your
questions in one of the Microchip forums:
http://www.microchip.com/forums/Forums
KansaiRobot



Joined: 25 Nov 2015
Posts: 5

View user's profile Send private message

PostPosted: Thu Nov 26, 2015 7:17 pm     Reply with quote

I see. Thank you for the indication.

Your explanation of the Frequency was very useful too. Very much grateful for that too Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group