AtomSoft
Well-Known Member
Hey guys i have been working on this for a day now and am stuck. I have tried so many things and no luck.
I have this Touch Screen Controller "AR1020"... im trying to communicate via SPI with no success. Can someone point to me where i am going wrong?
I have this Touch Screen Controller "AR1020"... im trying to communicate via SPI with no success. Can someone point to me where i am going wrong?
Code:
/* *****************************************************************************
; *
; Filename: *
; Date: *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;***************************************************************************** */
#include <p18f248.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = HS
/************************************
Prototypes
*************************************/
void main(void);
unsigned char writeSPI( unsigned char b);
void initSPI( void);
unsigned char buff[13];
#define NDSCS LATCbits.LATC2
/************************************
Main
*************************************/
void main(void){
unsigned char x=0;
TRISA = TRISB = TRISC = 0x00;
LATA = LATB = LATC = 0x00;
initSPI();
NDSCS = 0; //ONLY 1 SPI Device so leave low
while(1){
for(x=0;x<13;x++)
buff[x] = 0;
buff[0] = writeSPI(0x55);
buff[0] = writeSPI(0x01);
buff[0] = writeSPI(0x12);
while(x<8){
buff[x] = writeSPI(0);
}
Delay10KTCYx(20);
}
}
void initSPI( void)
{
TRISC = 0b00010000;
SSPCON1 = 1;
SSPCON1bits.SSPEN = 0;
SSPCON1bits.CKP = 0;
SSPSTATbits.CKE = 1;//1
SSPSTATbits.SMP = 0;
SSPCON1bits.SSPEN = 1;
}
unsigned char writeSPI( unsigned char b)
{
SSPBUF = b; // write to buffer for TX
while( !SSPSTATbits.BF); // wait transfer complete
return SSPBUF; // read the received value
}