Hey guys, I could use a bit of help. I'm stuck trying to figure out this controller. I found some sample drivers in the GLCD and touch screen: tutorials, code and infothread. I have tried to break it apart a bit and understand it:
I currently have the graphics LCD completely working where I can output lines/colors/images, etc.
The setup I am using is as follows:
____________________________
IDE: MPLAB X using C32
uC: pic32mx795F512H (64pin LQFP) running at 80MHz
Graphics LCD: YX32B 320x240 pixel display module
Touch screen controller:ADS7843
The questions I have are as follows:
____________________________
1. What SPI clock speed should I have? Currently (if you look at the code I posted) I have it configured to 2MHz.
2. I'm looking at the data sheet and the AD2-AD0 lines are bit confusing to me, can anyone clear this up?
3. The display module doesn't have a "busy" pin out? Is it really needed? Currently I am using an external interrupt and using a flag in main to call the function.
4. For calibration I have found this example. Does anyone have any advice as to how to go about calibrating the touch screen?
5. So far, I have the interrupt working where if I press the screen it changes the color. So, this means it should be configured properly. What I am doing now is trying to display the coordinates touched on the graphics LCD. I only get 0 and 249, which makes me believe either the calibration is incorrect for my touch screen or my SPI clock is wrong or something else. Does any one have any foresight as to what may be the problem?
If anyone can answer any of the above questions or clarify the basic communication to the ADS7843 that would really help a lot. As always thank you so much for your time and I appreciate any help/responses. Thank you.
EDIT:
The line with "SPI_OPEN_MODE8" that is commented out does not work I have to use SPICON_MODE16 for some reason. I also changed "unsigned char readX, readY;" to "unsigned short readX, readY;" and I now see the x change, but not the y, it is still stuck at "239."
Code:
unsigned short coordXresult;
unsigned short coordYresult;
#define SpiChn SPI_CHANNEL4
#define Touch_PenIRQ !PORTDbits.RD11
#define Touch_PenIRQ_TRIS TRISDbits.TRISD11
#define Touch_PenIRQ_LAT LATDbits.LATD11
#define Touch_CS LATDbits.LATD8
#define Touch_CS_TRIS TRISDbits.TRISD8
void Touch_Init(void) // Initialises the touch screen
{
Touch_CS = 1; // Deasserts the CS line.
//Touch_Busy_TRIS = 1;
Touch_PenIRQ_TRIS = 1;
// Initialize SPI hardware module pg. 206/314 of C32 user guide
// SPI Channel (set to 2), Set uC as Master, clock polarity cotrol, baud rate
// Try: SPICON_MSTEN|SPICON_CKP|SPICON_MODE8
// Baud Rate = BR = Fpb/(2*(SPIBRG+1)), Fpb is 1:1 => 80MHz
// Baud RAte = 80MHz/(2*(2MHz+1))=>20
//SpiChnOpen(SpiChn, SPI_OPEN_MSTEN|SPI_OPEN_CKP_HIGH|SPI_OPEN_MODE8, 10); // SpiChn defined in ADS7843.h. Master enabled, framing disabled
SpiChnOpen(SpiChn, SPICON_MSTEN|SPICON_CKP|SPICON_MODE16|SPICON_ON,20);
Touch_CS = 0;
TDelay();
// See pg. 6 and 9 of 18 in ADS7843 datasheet/ pg.21 of XPT2046
// S = start bit, A=addressing-input for multiplexer, MODE=selects ADC resolution PD = power down bits for idle
// Bits 0 -> 7 = S A2 A1 A0 MODE SFR/DFRnot PD1 PD0
SpiChnPutC(SpiChn, 0b10011100); // Sends the initialisation byte
//SpiChnGetC(SpiChn); //<--- ** causes error stall program
Touch_CS = 1;
}
void ReadTouchXY(void)
{
unsigned char readX, readY; //rdx2,rdx1
Touch_PenIRQ_TRIS = 0; // Sets the PenIRQ to an output
Touch_PenIRQ_LAT = 0; // Drives the PenIRQ low so the diode is not forward biased
Touch_CS = 0;
TDelay(); // Asserts the CS line and gives a required delay
SpiChnPutC(SpiChn, 0b11011100); // Sends the control byte
SpiChnGetC(SpiChn); // Reads the dummy data to clear the receive buffer
SpiChnPutC(SpiChn, 0x00); // Sends a dummy byte in order to clock the data out
readY = SpiChnGetC(SpiChn); // Puts the received data into rxd1
SpiChnPutC(SpiChn, 0b10011100); // Sends the next control byte to read the other axis
readX = SpiChnGetC(SpiChn); // Reads the lower byte of the first received data
// The following figure is the result (rxd1 & rxd2) inverted (4096-) - the offset (measured) * the range
coordYresult = 4096-(readY<<5) + (readX>>3);
if(coordYresult<Ymin)
coordYresult = 0;
else{
coordYresult -= Ymin;
coordYresult *= Yrange;}
if(coordYresult>239)
coordYresult = 239;
SpiChnPutC(SpiChn, 0x00); // Sends dummy data
readY = SpiChnGetC(SpiChn); // Places the received data into rxd1
SpiChnPutC(SpiChn, 0b10011100); // Sends dummy data
readX = SpiChnGetC(SpiChn); // Places the received data into rxd2
// The following figure is the result (rxd1 & rxd2) - the offset (measured) * the range
coordXresult = ((readY<<5) + (readX>>3));
if(coordXresult<Xmin)
coordXresult = 0;
else {
coordXresult -= Xmin;
coordXresult *= Xrange;}
if(coordXresult>319)
coordXresult = 319;
Touch_CS = 1; // Deasserts the chip select line
Touch_PenIRQ_TRIS = 1; // Sets the PenIRQ to an input again
//}
}
I currently have the graphics LCD completely working where I can output lines/colors/images, etc.
The setup I am using is as follows:
____________________________
IDE: MPLAB X using C32
uC: pic32mx795F512H (64pin LQFP) running at 80MHz
Graphics LCD: YX32B 320x240 pixel display module
Touch screen controller:ADS7843
The questions I have are as follows:
____________________________
1. What SPI clock speed should I have? Currently (if you look at the code I posted) I have it configured to 2MHz.
2. I'm looking at the data sheet and the AD2-AD0 lines are bit confusing to me, can anyone clear this up?
3. The display module doesn't have a "busy" pin out? Is it really needed? Currently I am using an external interrupt and using a flag in main to call the function.
4. For calibration I have found this example. Does anyone have any advice as to how to go about calibrating the touch screen?
5. So far, I have the interrupt working where if I press the screen it changes the color. So, this means it should be configured properly. What I am doing now is trying to display the coordinates touched on the graphics LCD. I only get 0 and 249, which makes me believe either the calibration is incorrect for my touch screen or my SPI clock is wrong or something else. Does any one have any foresight as to what may be the problem?
If anyone can answer any of the above questions or clarify the basic communication to the ADS7843 that would really help a lot. As always thank you so much for your time and I appreciate any help/responses. Thank you.
EDIT:
The line with "SPI_OPEN_MODE8" that is commented out does not work I have to use SPICON_MODE16 for some reason. I also changed "unsigned char readX, readY;" to "unsigned short readX, readY;" and I now see the x change, but not the y, it is still stuck at "239."
Last edited: