I try a touch screen controller ( XPT2046 ) with a PIC16F1704 ( master mode )
I see data coming in with the oscilloscope, only the PIC dont change a value.
What am i doing wrong ?
#pragma config CLKOUTEN = OFF, WDTE = OFF, PWRTE = OFF, CP = ON, BOREN = OFF, FCMEN = OFF, MCLRE = OFF, IESO = OFF, FOSC = INTOSC
#pragma config PPS1WAY = OFF, STVREN = ON, LPBOR = OFF, BORV = LO, ZCDDIS = ON, config LVP = OFF, WRT = OFF, PLLEN = ON
#define _XTAL_FREQ 32000000
#include<xc.h>
#define DACOUT DAC1CON1bits.DAC1R
void main( void )
{
TRISA = 0b001000;
TRISC = 0b101001;
RC1PPS = 0b10000; // SCK/SCL
RC2PPS = 0b10010; // SDO
SSPDATPPS = 0b10011; // RC3
DAC1CON0 = 0b10010000;
ANSELA = 0b00000;
ANSELC = 0b0000;
OSCCONbits.SCS = 0b00;
OSCCONbits.IRCF = 0b1110;
CM1CON0 = 0;
CM2CON0 = 0;
OPTION_REG = 0b10000111;
SSP1STAT = 0b00000000;
SSP1CON1 = 0b00100010;
__delay_ms( 100 );
for( ;; )ReadTouchScreen();
}
#define CS RC4
#define IRQ !RC0
unsigned char dummy,temp1,temp2;
void ReadTouchScreen()
{
if( IRQ )
{
CS = 0;
SSPBUF = 0b10011001;
while( !BF );
dummy = SSPBUF;
SSPBUF = 0;
while( !BF );
temp1 = SSPBUF;
SSPBUF = 0;
while( !BF );
temp2 = SSPBUF;
DACOUT = temp1;
CS = 1;
}
}
thank you