I can see the include file but it looks initially hard. How to slow it down?
It looks all software.
' XPT2046 routines for the GCBASIC compiler' Copyright (C) 2018-2020 Evan R. Venn' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA' v0.9e - more samples' v0.9f - revised calibration method' v0.9g - changed the IRQ' v.100 - first formal release''' '******************************************************************************************************''''Setup the XPT2046'''''''Typical calibration range for Hardware SPI when using XPT2046''' 'for 320 * 240 screeen... may be different for others'''#define XPT2046XMIN 17''' #define XPT2046YMIN 15'''#define XPT2046XMAX 100''' #define XPT2046YMAX 110'''''' 'Typical Calibration range for Software SPI when using XPT2046'''' #define XPT2046XMIN 30'''' #define XPT2046YMIN 25'''' #define XPT2046XMAX 210'''' #define XPT2046YMAX 225'''''''''#define XPT2046_DI DIGITAL_12 ' Data in | MISO. Should be shared port the GLCD (it will be if hardware SPI is used). No essential to define as the librart will select the GLCD port''' #define XPT2046_DO DIGITAL_11 ' Data out | MOSI. . Should be shared port the GLCD (it will be if hardware SPI is used). No essential to define as the librart will select the GLCD port'''#define XPT2046_SCK DIGITAL_13 ' Clock Line. . Should be shared port the GLCD (it will be if hardware SPI is used). No essential to define as the librart will select the GLCD port''''''#define XPT2046_CS DIGITAL_2 ' Touch chip select line. MUST BE DEFINED.''' #define XPT2046_IRQ ANALOG_5 ' Event line... something touched the GLCD touch sensor. MUST BE DEFINED.'''#define XPT2046_HardwareSPI ' remove/comment out if you want to use software SPI - must use same method as GLCD'''''''******************************************************************************************************'No change below here#define XPT2046_ReadSamples 200#define XPT2046_CFG_START 128 'bit 7#define XPT2046_CFG_MUX 112 'bits 7-4 the channel select bits A2, A1 & A0#define XPT2046_MUX_Y 80#define XPT2046_MUX_X 16#define XPT2046_MUX_Z1 48#define XPT2046_MUX_Z2 64#define XPT2046_CFG 8#define XPT2046_CFG_8BIT 8 'bit 3 - the 12 or 8 bit conversion#define XPT2046_CFG_12BIT 0#define XPT2046_CFG 4#define XPT2046_CFG_SER 4 'bit 2 - Single-ended or Differential conversion#define XPT2046_CFG_DFR 0#define XPT2046_CFG_PWR 0 'bit 1-0 - the power mask. PD1 & PD0#define XPT2046_CFG_PWR_1 1 'bit 1-0 - the power mask. PD1 & PD0#define XPT2046_CFG_PWR_2 2 'bit 1-0 - the power mask. PD1 & PD0#define XPT2046_CFG_PWR_3 3 'bit 1-0 - the power mask. PD1 & PD0#script'Test, map to the GLCD pins if they existXPT2046_DI_PORT=0ifXPT2046_DIThenXPT2046_DI_PORT=1endififXPT2046_DI_PORT=0ThenifGLCD_DIThenXPT2046_DI=GLCD_DIXPT2046_DI_PORT=1endifendififXPT2046_DI_PORT=0ThenWarning"Missing Port Assignment XPT2046_DI"endifXPT2046_DO_PORT=0ifXPT2046_DOThenXPT2046_DO_PORT=1endififXPT2046_DO_PORT=0ThenifGLCD_DOThenXPT2046_DO=GLCD_DOXPT2046_DO_PORT=1endifendififXPT2046_DO_PORT=0ThenWarning"Missing Port Assignment XPT2046_DO"endifXPT2046_SCK_PORT=0ifXPT2046_SCKThenXPT2046_SCK_PORT=1endififXPT2046_SCK_PORT=0ThenifGLCD_SCKThenXPT2046_SCK=GLCD_SCKXPT2046_SCK_PORT=1endifendififXPT2046_SCK_PORT=0ThenWarning"Missing Port Assignment XPT2046_SCK"endifXPT2046_CS_PORT=0ifXPT2046_CSThenXPT2046_CS_PORT=1endififXPT2046_CS_PORT=0ThenWarning"Missing Port Assignment XPT2046_CS"endifXPT2046_IRQ_PORT=0ifXPT2046_IRQThenXPT2046_IRQ_PORT=1endififXPT2046_IRQ_PORT=0ThenWarning"Missing Port Assignment XPT2046_IRQ"endif#endscript#startup Init_XPT2046, 99dimXTouchPoint_XPT2046,YTouchPoint_XPT2046asWorddimXTouchPoint_XPT2046raw,YTouchPoint_XPT2046rawasworddimXPT2046_Xmin,XPT2046_Ymin,XPT2046_Xmax,XPT2046_YmaxasBytedimCurrent_GLCD_WIDTH,Current_GLCD_HEIGHTaswordSubInit_XPT2046(OptionalInprecision=PREC_EXTREME)XPT2046_Xmin=XPT2046XMINXPT2046_Ymin=XPT2046YMINXPT2046_Xmax=XPT2046XMAXXPT2046_Ymax=XPT2046YMAXDIRXPT2046_DIINDIRXPT2046_IRQINDIRXPT2046_DOOUTDIRXPT2046_SCKOUTDIRXPT2046_CSOUT#ifdef XPT2046_HardwareSPI' harware SPI modeasmshowdebugSPIconstantusedequatestoHWSPIMODESCRIPTSPIModeHWSPIMODESCRIPT,0#endifRepeat4setXPT2046_CSOFFwait10mssetXPT2046_CSONwait10msEndRepeat#define isTouched_XPT2046 XPT2046_IRQ = 1EnableIRQ_XPT2046EndSubdimCurrent_GLCD_WIDTH,Current_GLCD_HEIGHTaswordsubSetCalibation_XPT2046(XPT2046_Xminasword,XPT2046_Xmaxasword,XPT2046_Yminasword,XPT2046_Ymaxasword)'this simply set the variablesEndSubsubSetCalibation_XPT2046(XPT2046_Xminasword,XPT2046_Xmaxasword,XPT2046_Yminasword,XPT2046_Ymaxasword,Current_GLCD_WIDTHasword,Current_GLCD_HEIGHTasword)'this simply set the variablesEndSubSubEnableIRQ_XPT2046setXPT2046_CSOFFSendData_XPT2046(XPT2046_CFG_START|XPT2046_CFG_8BIT|XPT2046_CFG_DFR|XPT2046_MUX_Y)wait1mssetXPT2046_CSONEndSub'''Send a data byte to the XPT2046 GLCD'''@paramXPT2046SendByteBytetosend'''@hidesub TransferData_XPT2046( IN XPT2046SendByte as byte, XPT2046OutByte as byte ) Dim XPT2046OutByte as byte XPT2046OutByte = 0 #ifdef XPT2046_HardwareSPI SPITransfer XPT2046SendByte, XPT2046OutByte #endif #ifndef XPT2046_HardwareSPI repeat 8 if XPT2046SendByte.7 = ON then set XPT2046_DO ON; else set XPT2046_DO OFF; end if SET XPT2046_SCK On; if XPT2046_DI = 1 then XPT2046OutByte.0 = 1 end if rotate XPT2046OutByte left rotate XPT2046SendByte left set XPT2046_SCK Off; end Repeat #endif' wait 250 usend Sub'''SendacommandtotheXPT2046GLCD'''@param XPT2046SendByte Command to send'''@hidesubSendData_XPT2046(INXPT2046SendByteasbyte)#ifdef XPT2046_HardwareSPISPITransferXPT2046SendByte,XPT2046TempOut#endif#ifndef XPT2046_HardwareSPIsetXPT2046_SCKOff;repeat8ifXPT2046SendByte.7=ONthensetXPT2046_DOON;elsesetXPT2046_DOOFF;endifSETXPT2046_SCKOn;rotateXPT2046SendByteleftsetXPT2046_SCKOff;endrepeat#endifendSubSubGetXY_XPT2046(outXTouchPoint_XPT2046asword,outYTouchPoint_XPT2046asword)''#define XPT2046_CFG_START 128 'bit7''#define XPT2046_CFG_MUX 112 'bits7-4thechannelselectbitsA2,A1&A0'#define XPT2046_MUX_Y 80'#define XPT2046_MUX_X 16'#define XPT2046_MUX_Z1 48'#define XPT2046_MUX_Z2 64'''#define XPT2046_CFG 8'#define XPT2046_CFG_8BIT 8 'bit3-the12or8bitconversion.Lowis12bit,Highis8bit'#define XPT2046_CFG_12BIT 0''#define XPT2046_CFG 4'#define XPT2046_CFG_SER 4 'bit2-Single-endedorDifferentialconversion'#define XPT2046_CFG_DFR 0''#define XPT2046_CFG_PWR 0 'bit1-0-thepowermask.PD1&PD0'#define XPT2046_CFG_PWR_1 1 'bit1-0-thepowermask.PD1&PD0'#define XPT2046_CFG_PWR_2 2 'bit1-0-thepowermask.PD1&PD0'#define XPT2046_CFG_PWR_3 3 'bit1-0-thepowermask.PD1&PD0dimXTouchPoint_XPT2046,YTouchPoint_XPT2046asWorddimNewXTouchPoint_XPT2046,NewYTouchPoint_XPT2046asWorddimXTouchPoint_XPT2046raw,YTouchPoint_XPT2046RawasworddimCurrent_GLCD_WIDTH,Current_GLCD_HEIGHTaswordsetXPT2046_CSOFFRepeat10TransferData_XPT2046(XPT2046_CFG_START|XPT2046_CFG_8BIT|XPT2046_CFG_DFR|XPT2046_MUX_X|XPT2046_CFG_PWR),XPT2046TempOutTransferData_XPT20460,YTouchPoint_XPT2046TransferData_XPT2046(XPT2046_CFG_START|XPT2046_CFG_8BIT|XPT2046_CFG_DFR|XPT2046_MUX_Y|XPT2046_CFG_PWR),XPT2046TempOutTransferData_XPT20460,XTouchPoint_XPT2046TransferData_XPT20460,XPT2046TempOutendRepeatXTouchPoint_XPT2046=0YTouchPoint_XPT2046=0RepeatXPT2046_ReadSamplesTransferData_XPT2046XPT2046_CFG_START|XPT2046_CFG_8BIT|XPT2046_CFG_DFR|XPT2046_MUX_X|XPT2046_CFG_PWR,XPT2046TempOutwait20usTransferData_XPT20460,NewYTouchPoint_XPT2046TransferData_XPT2046XPT2046_CFG_START|XPT2046_CFG_8BIT|XPT2046_CFG_DFR|XPT2046_MUX_Y|XPT2046_CFG_PWR,XPT2046TempOutwait20usTransferData_XPT20460,NewXTouchPoint_XPT2046TransferData_XPT20460,XPT2046TempOutyTouchPoint_XPT2046=(yTouchPoint_XPT2046+NewyTouchPoint_XPT2046)XTouchPoint_XPT2046=(XTouchPoint_XPT2046+NewXTouchPoint_XPT2046)EndRepeatyTouchPoint_XPT2046=yTouchPoint_XPT2046/(XPT2046_ReadSamples)xTouchPoint_XPT2046=xTouchPoint_XPT2046/(XPT2046_ReadSamples)SendData_XPT2046(XPT2046_CFG_START|XPT2046_CFG_8BIT|XPT2046_CFG_DFR|XPT2046_CFG_PWR|XPT2046_MUX_Y)setXPT2046_CSON'Set the raw values, folks may want to know thisXTouchPoint_XPT2046raw=XTouchPoint_XPT2046YTouchPoint_XPT2046Raw=yTouchPoint_XPT2046'Scale to calibrationXTouchPoint_XPT2046=scale(XTouchPoint_XPT2046,XPT2046_Xmin,XPT2046_Xmax,0,Current_GLCD_WIDTH)YTouchPoint_XPT2046=scale(YTouchPoint_XPT2046,XPT2046_Ymin,XPT2046_Ymax,0,Current_GLCD_HEIGHT)EndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The theory - the SPI frequency is too high. This is intended to resolve. I still may be wrong about this but only testing will isolate the issue.
We know some things about the XPT.
We know software SPI works. But, slower that hardware SPI. Insight: Software SPI is OK...therefore do not touch.
We know hardware SPI works when the chip is less than 32 mHz. So, Hardware SPI in principle is good.
We know hardware SPI can be set a different frequencies and if we select a slower hardware SPI frequency the XPT works but the GLCD is slow.
We know that all XPT communications from the user program uses sub SendData_XPT2046( ) and this method uses the low level SPITransfer() method.
We know that all GLCD communications from the user program uses a sub to send data and this method uses the low level SPITransfer() method. The same method as the XPT
We know this issue is specific to the LGT chip family and when running at 32 Mhz.
We know that the LGTs are chip family 122.
We know to set the SPI frequency is set using the SPIMode command.
We know that from an XPT library point of view that we do not know what frequency the user has selected for the chip or SPI. So, we will have to support all SPI frequency ranges.
We can therefore conclude the correct place to slow the XPT down is on the XPT library. Specifically, the SendData_XPT2046( ) method and ONLY the hardware section of the method.
We know we do not want to break stuff so we can adapt the method as follows. This is not tested and you will have to test. Replace the above code with the following code. This code should address the nine points above.
This uses conditional compilation to determine whether to use the new approach.
Please ignore the color coding.. this is something in the post.
#ifdef XPT2046_HardwareSPI#if ChipFamily <> 122'use this for non-LGT chips SPITransferXPT2046SendByte,XPT2046TempOut#endif#if ChipFamily = 122'is this an LGT chip?#if CHIPMHZ = 32'is the frequency equal to 32'DEFINE a constant. Mastet may work.. may have to be be MasterSlow#DEFINE LGT_XPT_HWSPIMODE MASTER'check the currect settingSelectCaseSPICurrentModeCaseMasterUltraFastSPIModeLGT_XPT_HWSPIMODE,0CaseMasterFastSPIModeLGT_XPT_HWSPIMODE,0CaseMaster'do nothing leave as isCaseMasterSlow'do nothing leave as isEndSelectSPITransferXPT2046SendByte,XPT2046TempOut'restore the SPI settingSPIModeHWSPIMODESCRIPT,0#endif#endif#if CHIPMHZ <> 32'Handle the non 32mHz chips using this method.SPITransferXPT2046SendByte,XPT2046TempOut#endif#endif
Then, do the same in the TransferData_XPT2046() method. But, ensure XPT2046OutByte is used not XPT2046TempOut in the newly added code segment.
You may need to turn off SPI (therefore add this to the new section) to change the frequency on the fly, you therefore may need to turn off before restoring. If you get a glitching on the signals using a protocol analyser.
You may need to change LGT_XPT_HWSPIMODE to MasterSlow. Only testing on an LGT will determine what works. So, try Master then change the constant to MasterSlow.
You may need to change the ChipmHz test to cover 16mHz and 32mHz. You will need to test all frequencies.
And, when you have tested the LGT. This will need testing on an UNO to make sure that still works.
Test, adapt and test the UNO, then retest the LGT, then, post (as an attachment) the working library. Thank you.
Enjoy....
Last edit: Anobium 2021-08-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Anobium. I'll sort out a test board... the kitchen is not really a workshop nor is the coffee table in the living room, so when I finish experimenting, I've got to put stuff away then can't find it :)
I should have learnt how serial works from a "bit banging" view but the "computers" I learnt on in the early '80s didn't have serial, like sinclair or amstrad. Only the BBC micro had a rs232 port and cost the same as a second hand car!
First thing I ever connected to a rs232 port was a picaxe because I was too mean to buy the picaxe usb solution.
Wish I had sourced a 3.3V logic ili9341 as using two 8 channel logic level converters creates a birds nest and that's when wiring errors occur.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks again. I got a cheap usb logic analyser, saetek or saelek clone for £2 odd and the real software I got free download. Maybe I'll use that.
My scope is just a 2 channel usb hantek but might be useful... the openhantek software is better than the real hantek software.
I might learn something.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Anobium. This is the lgt328/ili9341/xpt touch code I am using. It doesn't work.
It does work if you change
#define XPT2046_DI DIGITAL_12 ' Data in | MISO
#define XPT2046_DO DIGITAL_11 ' Data out | MOSI
to
#define XPT2046_DI DIGITAL_11 ' Data in | MISO
#define XPT2046_DO DIGITAL_12 ' Data out | MOSI
this using sofware spi.
Is there a later version of this program please?
'''A demonstration program for GCGB and GCB.'''--------------------------------------------------------------------------------------------------------------------------------'''This program is a simple GLCD demonstration of the ILI9341 GLCD with the XPT2046 Touch capabilities.'''ItisanicegraphicalLCD,suitableforalotofvariousprojects.'''This program shows the calibration of the touch with the specific GLCD.'''TheGLCDisconnectedtothemicroprocessorasshowninthehardwaresectionofthiscode.''':'''ThishasbeentestedusingthehardwareandsoftwareSPIoption.''':'''Note:forthecorrectoperationofthisdisplayyouMUSTconnectviaaCD4050,seehttp://forum.arduino.cc/index.php?topic=181679.90''':'''@author'''@licence GPL'''@version1.1'''@date'''********************************************************************************'Chip Settings.#chip LGT8F328P,32#option explicit#include <lgt8f328p.h>#include <glcd.h>#include <xpt2046.h>'******************************************************************************************************'Setup the GLCD#define GLCD_TYPE GLCD_TYPE_ILI9341'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI#define GLCD_DC DIGITAL_8 ' Data command line#define GLCD_CS DIGITAL_10 ' Chip select line#define GLCD_RESET DIGITAL_9 ' Reset line#define GLCD_DI DIGITAL_12 ' Data in | MISO - Not used therefore not really required#define GLCD_DO DIGITAL_11 ' Data out | MOSI#define GLCD_SCK DIGITAL_13 ' Clock Line#define ILI9341_HardwareSPI ' remove/comment out if you want to use software SPI.'Optionally, you can define the HWSPIMode by using #define HWSPIMode masterfast where #define HWSPIMode is masterslow|master|masterfast'This will overwrite the default in the GLCD library. This is so users do not have to change the library.'the default is "masterfast"'The following example is commented out intentionally'#define HWSPIMode masterfast'******************************************************************************************************'Setup the XPT2046'Typical calibration range for Hardware SPI when using XPT2046'for 320 * 240 screeen... may be different for others#define XPT2046XMIN 15#define XPT2046YMIN 14#define XPT2046XMAX 110#define XPT2046YMAX 113#define XPT2046_ReadSamples 15'Typical Calibration range for Software SPI when using XPT2046' #define XPT2046XMIN 30' #define XPT2046YMIN 25' #define XPT2046XMAX 210' #define XPT2046YMAX 225#define XPT2046_DI DIGITAL_12 ' Data in | MISO#define XPT2046_DO DIGITAL_11 ' Data out | MOSI#define XPT2046_SCK DIGITAL_13 ' Clock Line#define XPT2046_CS DIGITAL_2 ' Chip select line#define XPT2046_IRQ ANALOG_5#define XPT2046_HardwareSPI ' remove/comment out if you want to use software SPI - must use same method as GLCD'Optionally, you can define the HWSPIMode by using #define HWSPIMode masterfast where #define HWSPIMode is masterslow|master|masterfast'This will overwrite the default in the XPT2046 library. This is so users do not have to change the library.'the default is "masterfast"'The following example is commented out intentionally'#define HWSPIMode masterfast'Set the initial calibration - shown here to show the method.'If you rotate the screen then you will have to call the method to reset these parameters.SetCalibation_XPT2046(XPT2046XMIN,XPT2046XMAX,XPT2046YMIN,XPT2046YMAX,GLCD_WIDTH,GLCD_HEIGHT)'******************************************************************************************************'Main programGLCDRotatePortrait_RevGLCDCLSTFT_NAVYSetCalibation_XPT2046(XPT2046XMIN,XPT2046XMAX,XPT2046YMIN,XPT2046YMAX,GLCD_WIDTH,GLCD_HEIGHT)ScreenLayoutdimXconverge,YconvergeasIntegerdimconvergeCounterasbytedoXconverge=0Yconverge=0convergeCounter=1filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_RED'always wait for touch eventwaitwhileisTouched_XPT2046filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_YELLOWdorepeat5'get the values -GetXY_XPT2046(XTouchPoint_XPT2046,YTouchPoint_XPT2046)endRepeat'test for settling by testing for converganceifABS((Xconverge-XTouchPoint_XPT2046))>1orABS((Yconverge-YTouchPoint_XPT2046))>1thenXconverge=XTouchPoint_XPT2046Yconverge=YTouchPoint_XPT2046convergeCounter++Else'convergedexitdoendifLoop'Flip the data to handle for the screen rotationYTouchPoint_XPT2046=Current_GLCD_HEIGHT-YTouchPoint_XPT2046filledboxCurrent_GLCD_WIDTH,0,Current_GLCD_WIDTH-10,10,TFT_GREENifXTouchPoint_XPT2046>Current_GLCD_WIDTH-59andYTouchPoint_XPT2046>Current_GLCD_HEIGHT-20thenifXTouchPoint_XPT2046<Current_GLCD_WIDTHandYTouchPoint_XPT2046<Current_GLCD_HEIGHTthen'clearScreenLayoutendifelseFilledCircleXTouchPoint_XPT2046,YTouchPoint_XPT2046,3,TFT_LIGHTGREY'Show the raw dataGLCDPrint(24,56,pad(str(XTouchPoint_XPT2046raw),3))GLCDPrint(24,72,pad(str(YTouchPoint_XPT2046raw),3))GLCDPrint(24,90,pad(str(convergeCounter),3))'Automatically adjust the values to min and max'Not needed in a real program use SetCalibation_XPT2046( XPT2046_Xmin, XPT2046_Xmax, XPT2046_Ymin, XPT2046_Ymax )ifXTouchPoint_XPT2046raw<XPT2046_XminthenXPT2046_Xmin=XTouchPoint_XPT2046rawifYTouchPoint_XPT2046raw<XPT2046_YminthenXPT2046_Ymin=YTouchPoint_XPT2046rawifXTouchPoint_XPT2046raw>XPT2046_XmaxthenXPT2046_Xmax=XTouchPoint_XPT2046rawifYTouchPoint_XPT2046raw>XPT2046_YmaxthenXPT2046_Ymax=YTouchPoint_XPT2046raw'show the valuesGLCDPrint(102,56,pad(str(XPT2046_Xmin),3))GLCDPrint(102,72,pad(str(XPT2046_Ymin),3))GLCDPrint(162,56,pad(str(XPT2046_Xmax),3))GLCDPrint(162,72,pad(str(XPT2046_Ymax),3))GLCDPrint(24,230,pad(str(XTouchPoint_XPT2046),5))GLCDPrint(24,246,pad(str(YTouchPoint_XPT2046),5))'do not hammer the touchwait100msendifloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You need to revert the port settings as these are the hardware ports. So, you need hardware and software working om same ports. So, change the connection to the GLCD.
No later code.
Last edit: Anobium 2021-08-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't tried your code. https://sourceforge.net/u/evanvennn/
May seem daft but I changed #chip LGT8F328P,32 to 16 it would be like a mega328 which does work with hwspi but the lgt didn't.
I can see in your demo that when the screen is touched the box top right goes from red to yellow so the touch input works. I think not sharing mosi and miso with the touch pins and a bitbang solution to get the data when the screen touch event occurs. No, I can't code that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Trying to understand what the post means. Is this what you mean ? and the state of play ?
Using the stock (therefore not modified using the info in this thread) SPI library.
Working at steps #3 to #8 means. The GLCD works and the XPT touch events work.
You have a working mega328p solution where the ILI and the XPT work in software mode. Therefore, using software SPI
You have a working mega328p solution where the ILI and the XPT work in hardware mode. Therefore, using hardware SPI
The above two tests work.
Then, you swapped out the mega328p for an lgt328p.
Using the same software SPI source (used at step #1) you changed the program to LGTchip and frequency to 16 ... what happened?
Using the same hardware SPI source (used at step #1) you changed the program to LGTchip and frequency to 16 ... what happened?
I do not know what demo you are watching. Which one? What is the chip etc etc?
Re bit banging... we are no where near coding. I do not understand the baseline yet. I need clarity re the tests above #3 to #8 before I can really comment on next steps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My bad, I'll try to clarify my progress.
under GCB@Syn/GreatCowbasic/Demos/touch_sensor_solutions there's a
glcd_xpt_demonstration_mega328p_for_ili9341.gcb which works with swspi and hwspi.
There's also a glcd_xpt2046_demonstration_for_lgtf328p_for_ili9341.gcb which works with swspi
but not with hwspi. The box top right of screen changes colour but no circles drawn or numbers changing.
You said this was because the lgt was too fast and overclocked the xpt.
The lgt demo uses #chip LGT8F328P ie not #chip LGT8F328P ,32
whereas #chip mega328p,16 is most common.
So I naively thought #chip LGT8F328P,16 would make it same speed as mega328p and so not overclock the xpt but hwspi still didn't work.
Another idea was not share TDIN and TDO ili pins with mosi and miso,
instead use them with swspi while the screen ran using hwspi.
I'll have to look at #include <xpt2046.h> but it's too much for me.
You have higher priorities than this. It's not a major problem, just a niggle.</xpt2046.h>
Last edit: Anobium 2021-08-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
GCB@Syn/GreatCowbasic/Demos/touch_sensor_solutions there's a
glcd_xpt_demonstration_mega328p_for_ili9341.gcb which works with swspi and hwspi.
OK
There's also a glcd_xpt2046_demonstration_for_lgtf328p_for_ili9341.gcb which works with swspi but not with hwspi. The box top right of screen changes colour but no circles drawn or numbers changing.
Did you make any connection changes? Therefore, you only changed the board with the chip.
Did you try 8mHz? 16mHz? and 32 mHz? What are the results across the frequencies?
You said this was because the lgt was too fast and overclocked the xpt.
Yes. This is what we are trying to determine the root cause of.
The lgt demo uses #chip LGT8F328P ie not #chip LGT8F328P ,32
These are the same frequency. Check the report window in the IDE to ensure the frequency is 32mHz.
whereas #chip mega328p,16 is most common.
OK
So I naively thought #chip LGT8F328P,16 would make it same speed as mega328p and so not overclock the xpt but hwspi still didn't work.
Did you only change the board with the chip? I need to know that no connections changed.
Another idea was not share TDIN and TDO ili pins with mosi and miso,
instead use them with swspi while the screen ran using hwspi.
We are no where near considering another approach. I do not yet understand the tests you have done. See questions above.
I'll have to look at #include <xpt2046.h> but it's too much for me.
You have higher priorities than this. It's not a major problem, just a niggle.</xpt2046.h>
Do not give up.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium, I can't just change the boards. The arduino and lgt are both nano boards and pin to pin the same but run at different logic levels. mega328 through logic converter... lgt straight wiring.
I use 2 breadboards and swap the many ili9341 displays I have to check display consistency and they are interchangeable so the same.
They mega328 wiring is not fun compared to lgt but it works, so I didn't mess up there.
@Kent I think said choose the logic level devices for your project but what if you have 2 devices at different logic? Which gets preference?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Anobiwan, "What happens if you try to run the arduino board in the lgt setup?"
the mega uses logic shifters so you can't just swap them.
I tried the ili9341 with just the graphic hwspi connected and got the simple glcd demo for mega328p working with lgt by just the #chip and include <lgf>.
It works fast so OK.
I then connected a scope to the touch IRQ line and it is high running the simple glcd demo but goes low when the screen is touched. It just does , honest.
I'm looking at the spi solutions in demos and the mega328 version which has a good swspi code example.
At the cost of 2 pins could the screen pressed event be used to start an on pin change interrupt to start the swspi code as a sub to read the touch data?
Am I wasting my time with this idea? </lgf>
ps. was lgt interrupts documented. I always copied mega328 interrupts same as pics cos they a bit hard but timercalc was handy.
Last edit: stan cartwright 2021-08-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Anobiwan, "What happens if you try to run the arduino board in the lgt setup?"
the mega uses logic shifters so you can't just swap them.
Why not? the logic shifter does not work... did you try?
I tried the ili9341 with just the graphic hwspi connected and got the simple glcd demo for mega328p working with lgt by just the #chip and include lgf It works fast so OK.
OK. I am assuming ( again ) the frequency is 32 and the Touch is not working.
I then connected a scope to the touch IRQ line and it is high running the simple glcd demo but goes low when the screen is touched. It just does , honest.
I would agree. The issue with the XPT is not the event but the read operation. The event working is a good sign that things are good.
I'm looking at the spi solutions in demos and the mega328 version which has a good swspi code example.
At the cost of 2 pins could the screen pressed event be used to start an on pin change interrupt to start the swspi code as a sub to read the touch data?
Am I wasting my time with this idea?
I think so.
ps. was lgt interrupts documented. I always copied mega328 interrupts same as pics cos they a bit hard but timercalc was handy.
Yes. There are a few more interrupts but the main interrupts are the same across the chips.
So, in summary. You have the LGT working in terms of GLCD writes and the XPT is raising the event.
Now. To figure out how to change the SPI frequency so the XPT works. The easy bit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So, attached is the LGT XPT demo updated to 32 mHz. This has a new constant LGT_XPT_HWSPIMODE. This constant defines the SPI operating mode of the XPT for the LGT. This constant is optional but I have included in the demo so you play with it.
The .h has been updated
1. To change the SPI frequency to the frequency specified by the constant LGT_XPT_HWSPIMODE. The changes are in TransferData_XPT2046() and SendData_XPT2046(). The changes are detailed in the earlier post in this thread.
2. To add a script section to determine is the user has set LGT_XPT_HWSPIMODE or not. If not, create a constant called LGT_XPT_HWSPIMODE set to MASTER
Do test. You can try #define LGT_XPT_HWSPIMODE MASTERSLOW or #define LGT_XPT_HWSPIMODE MASTERFAST. Hopefully MASTERSLOW works and MASTERFAST fails as MASTERFAST will set the SPI frequency to be too fast.
I'll check it out asap ... but I got my ebike stolen today... and I can't walk far so the half mile home was painful. totally.. I hope the thief fucks up recharging and sets the li-ion pack alight.
not really but I'm dissed off.
I will check your code asap. cheers sir.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Used your code and copied the h file to gcb includes.
Used #define LGT_XPT_HWSPIMODE MASTERSLOW https://youtu.be/IXt9-1WlGCc
It shows number changing but calibration is wrong.. change portrait_rev to portrait, same.
Getting somewhere.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know if I tested it correctly. Thanks for your work.
Ili9341 for graphics is fast. Getting touch sorted would be icing on the cake but both working hwspi would make it a handy cheap display.
The nextion displays work fine if you like the necessary gui needed but sending it serial commands and it's a slow display.
The ili displays at 320 x 240 and lots of colours is a nice display and works ok with lgt328.
The lgt speed increase shows when doing graphics. bit of trig and nice dials if you like dials.
Try the sprite demo on a nextion. No don't.
The pixel at x,y value on ili is great for graphic games,
The write data I ripped from your glcd is handy.
Ok. everything has to be universal in gcb but it's not. If there's stuff that is only sorted for one device doesn't mean it should be dismissed, it should be a bonus for using that device.
I think your lgt work is brill. The device has it's uses that 64MHz pic and 16 MHz avr couldn't do so cool you supported it.
I thought it would become more popular.
Sorry there's been problems but resolvable later. the lgt is cool as is. Well done.
Who wants to write games on a pic anyway?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know if I tested it correctly. Thanks for your work.
Do the XPT changes work ? Where you able to calibrate ?
Ili9341 for graphics is fast. Getting touch sorted would be icing on the cake but both working hwspi would make it a handy cheap display.
I guess the XPT is not sorted as this sentence refers to 'icing on the cake' which would mean it is not sorted.
The nextion displays work fine if you like the necessary gui needed but sending it serial commands and it's a slow display.
OK
The ili displays at 320 x 240 and lots of colours is a nice display and works ok with lgt328.
The lgt speed increase shows when doing graphics. bit of trig and nice dials if you like dials.
So, I think you are saying the ILI9341 GLCD works well.
Try the sprite demo on a nextion. No don't.
The pixel at x,y value on ili is great for graphic games,
The write data I ripped from your glcd is handy.
OK
Ok. everything has to be universal in gcb but it's not. If there's stuff that is only sorted for one device doesn't mean it should be dismissed, it should be a bonus for using that device.
Agree
I think your lgt work is brill. The device has it's uses that 64MHz pic and 16 MHz avr couldn't do so cool you supported it.
:-)
I thought it would become more popular.
Me too.
Sorry there's been problems but resolvable later. the lgt is cool as is. Well done.
Cheers. But, I need clarity on XPT on LGT.
Who wants to write games on a pic anyway?
We do!
Last edit: Anobium 2021-08-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can see the include file but it looks initially hard. How to slow it down?
It looks all software.
Stan, it supports hardware and software. See the checks for hardware and software SPI.
@Stan
The theory - the SPI frequency is too high. This is intended to resolve. I still may be wrong about this but only testing will isolate the issue.
We know some things about the XPT.
We can therefore conclude the correct place to slow the XPT down is on the XPT library. Specifically, the SendData_XPT2046( ) method and ONLY the hardware section of the method.
We know we do not want to break stuff so we can adapt the method as follows. This is not tested and you will have to test. Replace the above code with the following code. This code should address the nine points above.
This uses conditional compilation to determine whether to use the new approach.
Please ignore the color coding.. this is something in the post.
Then, do the same in the TransferData_XPT2046() method. But, ensure XPT2046OutByte is used not XPT2046TempOut in the newly added code segment.
You may need to turn off SPI (therefore add this to the new section) to change the frequency on the fly, you therefore may need to turn off before restoring. If you get a glitching on the signals using a protocol analyser.
You may need to change LGT_XPT_HWSPIMODE to MasterSlow. Only testing on an LGT will determine what works. So, try Master then change the constant to MasterSlow.
You may need to change the ChipmHz test to cover 16mHz and 32mHz. You will need to test all frequencies.
And, when you have tested the LGT. This will need testing on an UNO to make sure that still works.
Test, adapt and test the UNO, then retest the LGT, then, post (as an attachment) the working library. Thank you.
Enjoy....
Last edit: Anobium 2021-08-16
Thanks Anobium. I'll sort out a test board... the kitchen is not really a workshop nor is the coffee table in the living room, so when I finish experimenting, I've got to put stuff away then can't find it :)
I should have learnt how serial works from a "bit banging" view but the "computers" I learnt on in the early '80s didn't have serial, like sinclair or amstrad. Only the BBC micro had a rs232 port and cost the same as a second hand car!
First thing I ever connected to a rs232 port was a picaxe because I was too mean to buy the picaxe usb solution.
Wish I had sourced a 3.3V logic ili9341 as using two 8 channel logic level converters creates a birds nest and that's when wiring errors occur.
You need any serial or analysers if you are careful.
Ensure you have the existing libraries GLCD and XPT working before you start. Dont start editing XPT library until you have a working baseline.
Have fun
Thanks again. I got a cheap usb logic analyser, saetek or saelek clone for £2 odd and the real software I got free download. Maybe I'll use that.
My scope is just a 2 channel usb hantek but might be useful... the openhantek software is better than the real hantek software.
I might learn something.
Oh you will. :-)
Hi Anobium. This is the lgt328/ili9341/xpt touch code I am using. It doesn't work.
It does work if you change
to
this using sofware spi.
Is there a later version of this program please?
You need to revert the port settings as these are the hardware ports. So, you need hardware and software working om same ports. So, change the connection to the GLCD.
No later code.
Last edit: Anobium 2021-08-24
I haven't tried your code. https://sourceforge.net/u/evanvennn/
May seem daft but I changed #chip LGT8F328P,32 to 16 it would be like a mega328 which does work with hwspi but the lgt didn't.
I can see in your demo that when the screen is touched the box top right goes from red to yellow so the touch input works. I think not sharing mosi and miso with the touch pins and a bitbang solution to get the data when the screen touch event occurs. No, I can't code that.
Trying to understand what the post means. Is this what you mean ? and the state of play ?
I do not know what demo you are watching. Which one? What is the chip etc etc?
Re bit banging... we are no where near coding. I do not understand the baseline yet. I need clarity re the tests above #3 to #8 before I can really comment on next steps.
My bad, I'll try to clarify my progress.
under GCB@Syn/GreatCowbasic/Demos/touch_sensor_solutions there's a
glcd_xpt_demonstration_mega328p_for_ili9341.gcb which works with swspi and hwspi.
There's also a glcd_xpt2046_demonstration_for_lgtf328p_for_ili9341.gcb which works with swspi
but not with hwspi. The box top right of screen changes colour but no circles drawn or numbers changing.
You said this was because the lgt was too fast and overclocked the xpt.
The lgt demo uses #chip LGT8F328P ie not #chip LGT8F328P ,32
whereas #chip mega328p,16 is most common.
So I naively thought #chip LGT8F328P,16 would make it same speed as mega328p and so not overclock the xpt but hwspi still didn't work.
Another idea was not share TDIN and TDO ili pins with mosi and miso,
instead use them with swspi while the screen ran using hwspi.
I'll have to look at #include <xpt2046.h> but it's too much for me.
You have higher priorities than this. It's not a major problem, just a niggle.</xpt2046.h>
Last edit: Anobium 2021-08-26
OK
Did you make any connection changes? Therefore, you only changed the board with the chip.
Did you try 8mHz? 16mHz? and 32 mHz? What are the results across the frequencies?
Yes. This is what we are trying to determine the root cause of.
These are the same frequency. Check the report window in the IDE to ensure the frequency is 32mHz.
OK
Did you only change the board with the chip? I need to know that no connections changed.
We are no where near considering another approach. I do not yet understand the tests you have done. See questions above.
Do not give up.
Anobium, I can't just change the boards. The arduino and lgt are both nano boards and pin to pin the same but run at different logic levels. mega328 through logic converter... lgt straight wiring.
I use 2 breadboards and swap the many ili9341 displays I have to check display consistency and they are interchangeable so the same.
They mega328 wiring is not fun compared to lgt but it works, so I didn't mess up there.
@Kent I think said choose the logic level devices for your project but what if you have 2 devices at different logic? Which gets preference?
What happens if you try to run the arduino board in the lgt setup?
@Anobiwan, "What happens if you try to run the arduino board in the lgt setup?"
the mega uses logic shifters so you can't just swap them.
I tried the ili9341 with just the graphic hwspi connected and got the simple glcd demo for mega328p working with lgt by just the #chip and include <lgf>.
It works fast so OK.
I then connected a scope to the touch IRQ line and it is high running the simple glcd demo but goes low when the screen is touched. It just does , honest.
I'm looking at the spi solutions in demos and the mega328 version which has a good swspi code example.
At the cost of 2 pins could the screen pressed event be used to start an on pin change interrupt to start the swspi code as a sub to read the touch data?
Am I wasting my time with this idea? </lgf>
ps. was lgt interrupts documented. I always copied mega328 interrupts same as pics cos they a bit hard but timercalc was handy.
Last edit: stan cartwright 2021-08-27
I used a white led from touch IRQ to ground to show the pin behaving.
https://www.youtube.com/watch?v=YWs3Bg6Imbw
Why not? the logic shifter does not work... did you try?
OK. I am assuming ( again ) the frequency is 32 and the Touch is not working.
I would agree. The issue with the XPT is not the event but the read operation. The event working is a good sign that things are good.
I think so.
Yes. There are a few more interrupts but the main interrupts are the same across the chips.
So, in summary. You have the LGT working in terms of GLCD writes and the XPT is raising the event.
Now. To figure out how to change the SPI frequency so the XPT works. The easy bit.
Good to see the interrupt working
So, attached is the LGT XPT demo updated to 32 mHz. This has a new constant
LGT_XPT_HWSPIMODE
. This constant defines the SPI operating mode of the XPT for the LGT. This constant is optional but I have included in the demo so you play with it.The .h has been updated
1. To change the SPI frequency to the frequency specified by the constant
LGT_XPT_HWSPIMODE
. The changes are in TransferData_XPT2046() and SendData_XPT2046(). The changes are detailed in the earlier post in this thread.2. To add a script section to determine is the user has set
LGT_XPT_HWSPIMODE
or not. If not, create a constant calledLGT_XPT_HWSPIMODE
set to MASTERDo test. You can try
#define LGT_XPT_HWSPIMODE MASTERSLOW
or#define LGT_XPT_HWSPIMODE MASTERFAST
. Hopefully MASTERSLOW works and MASTERFAST fails as MASTERFAST will set the SPI frequency to be too fast.Enjoy.
Last edit: Anobium 2021-08-28
I'll check it out asap ... but I got my ebike stolen today... and I can't walk far so the half mile home was painful. totally.. I hope the thief fucks up recharging and sets the li-ion pack alight.
not really but I'm dissed off.
I will check your code asap. cheers sir.
Used your code and copied the h file to gcb includes.
Used #define LGT_XPT_HWSPIMODE MASTERSLOW
https://youtu.be/IXt9-1WlGCc
It shows number changing but calibration is wrong.. change portrait_rev to portrait, same.
Getting somewhere.
looks good. calibrate one direction then the other. lookong good.
I don't know if I tested it correctly. Thanks for your work.
Ili9341 for graphics is fast. Getting touch sorted would be icing on the cake but both working hwspi would make it a handy cheap display.
The nextion displays work fine if you like the necessary gui needed but sending it serial commands and it's a slow display.
The ili displays at 320 x 240 and lots of colours is a nice display and works ok with lgt328.
The lgt speed increase shows when doing graphics. bit of trig and nice dials if you like dials.
Try the sprite demo on a nextion. No don't.
The pixel at x,y value on ili is great for graphic games,
The write data I ripped from your glcd is handy.
Ok. everything has to be universal in gcb but it's not. If there's stuff that is only sorted for one device doesn't mean it should be dismissed, it should be a bonus for using that device.
I think your lgt work is brill. The device has it's uses that 64MHz pic and 16 MHz avr couldn't do so cool you supported it.
I thought it would become more popular.
Sorry there's been problems but resolvable later. the lgt is cool as is. Well done.
Who wants to write games on a pic anyway?
Wow - that is a summary. A few questions.
Do the XPT changes work ? Where you able to calibrate ?
I guess the XPT is not sorted as this sentence refers to 'icing on the cake' which would mean it is not sorted.
OK
So, I think you are saying the ILI9341 GLCD works well.
OK
Agree
:-)
Me too.
Cheers. But, I need clarity on XPT on LGT.
We do!
Last edit: Anobium 2021-08-30