Menu

ILI9341 and Soft SPI use

2023-09-18
2023-09-20
  • Steve Scott

    Steve Scott - 2023-09-18

    Hello All-
    I have been trying to use an ILI9341 with software serial on a PIC18F67K40 and I have been told the include file does work for both hardware and software SPI uses.
    I have looked at glcd.h and glcd_ili9341.h and do see where it looks like it will work, rather clever way to determine hardware of software use by using the 'DC' bit.
    I have searched for 'ILI9341 and software SPI' but did not see anyone using it.
    I have attached a logic analyzer which shows:
    Grey Trace is Data In
    Orange Trace is Clock
    Red Trace is Chip Select - active low
    Orange Trace is Command

    The things I noticed are the clock trace does not seem to clock all the time as it should. It is shared with another SPI device and it works fine, although different Chip Selects.
    The Data trace also looks weird and it is also shared with another SPI device and it works fine, although different Chip Selects.
    The Command trace should be going up and down? but it seems to be low all the time which means if it is used, is always in Command Mode.

    I have explicitly set GLCD_DC, GLCD_CS, GLCD_RESET (which I hold HIGH), GLCD_DI, and GLCD_DO.
    Also set the DIR for all the ports.
    I have also tried switching the GLCD_DI and GLCD_DO in case I misunderstood the datasheet for the ILI9341 to no avail. I have asked another user who bought this GLCD from Amazon if it was only 3.3 or 5v and he said he has used it with both voltage levels so I think the interface levels currently at 5v should be fine. The J1 jumper is NOT shorted.
    The software ports do only seem to 'wiggle' when the GLCD is being 'told' to do something so it seems the ports are correct.

    Wondering if anyone else has used software SPI on this or any other GLCD.
    Compiler does not throw any errors at all.

     
  • Anobium

    Anobium - 2023-09-18

    Lots of demos show how to use the ILI9341.

    See https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Vendor_Boards/Great_Cow_Basic_Demo_Board/18f27Q84_chiprange_demonstrations/260_spi_glcd_using_ili9341.gcb

    This is a specific 18F ILI9341 implementation using software SPI. The hardware SPI is not enabled therefore PPS is not set and the ILI9341 uses the ILI93141 software SPI methods.

    The basic program is

    #INCLUDE <glcd.h>
    #DEFINE GLCD_TYPE GLCD_TYPE_ILI9341
    
    'Pin mappings for ILI9341 can be any output port when not using PPS
    #DEFINE GLCD_DC porta.1
    #DEFINE GLCD_CS porta.2
    #DEFINE GLCD_RESET porta.3
    #DEFINE GLCD_DO portc.5
    #DEFINE GLCD_SCK portc.3
    
    GLCDCLS
    GLCDPrint 0,0, "hello world"
    
     
  • Steve Scott

    Steve Scott - 2023-09-18

    Thanks Evan, I have perused the demos as well.
    Will make this simple test and see what happens.
    Thanks.

     
  • Steve Scott

    Steve Scott - 2023-09-18

    That did not work.
    Going to see if I have a simpler board on which to try.
    May have a Clicker board from Mikro. If not, I will look for something simple.
    Thanks.

     
  • Anobium

    Anobium - 2023-09-18

    Want me to try here?

     
  • Steve Scott

    Steve Scott - 2023-09-18

    Can if you would like - still lookin' around to see what I may have around the lab.....

     
  • Anobium

    Anobium - 2023-09-19

    This worked. I connected the K40 and the ILI9341. Worked first attempt.

    So, may advice.

    1. Check the chip to GLCD connection by adding a Do: GLCD_DC=!GLCD_DC:Loopwhere you test each port assignment in turn. Do not add port output control because you will be using the port output control from the GLCD library. Here... I had the GLCD_DO on the incorrect port and this test helped me relocate the connection to the GLCD.
    2. Check the operating voltage of the ILI9341. I have many of them. Each one here is marked with its operating voltage tolerance. They range from 3v3 to 5v0. But, most will not operate above 4v0 - so, set the operating voltage of the whole circuit to 3v3. This is the general issue with these GLCDs... the operating specifications are not consistent.
    #CHIP 18F67K40
    #INCLUDE <glcd.h>
    #DEFINE GLCD_TYPE GLCD_TYPE_ILI9341
    
    'Pin mappings for ILI9341 can be any output port when not using PPS
    #DEFINE GLCD_DC porta.1
    #DEFINE GLCD_CS porta.2
    #DEFINE GLCD_RESET porta.3
    #DEFINE GLCD_DO portc.5
    #DEFINE GLCD_SCK portc.3
    
    
        GLCDCLS
        GLCDPrint 0,0, "hello world"
    
     
  • Steve Scott

    Steve Scott - 2023-09-19

    OK Group, I have found a simple little board on which to try this GLCD library.
    It is a MikroElectronica Click 2 PIC18FX which uses a PIC18F67K40.
    I am using the MikroBootLoader to get the test code into the proc.
    I have never used this bootloader but the doc says just hit RESET after the upload and it will start with my code.
    It is a blank screen.
    The LCD is powered by 3.3v and VCC is also 3.3v I have tried both of these at 5v but no difference.
    Screen seems to roll up from the bottom but no text is displayed.
    Code is attached for help.

     
    • Anobium

      Anobium - 2023-09-19

      I cannot review the code on my phone. But, if try clearing the screen to another color. glcdcls tft_blue or some other color. If this works then you know the communications are working.

      Try it, let me know results.

       
  • Steve Scott

    Steve Scott - 2023-09-19

    No joy here at the moment Evan. After reset screen rolls from the bottom and back to white or a whitish grey.
    Will keep after it......

     
    • Anobium

      Anobium - 2023-09-19

      The program. Remove the DIR and those RESETs. Those resets
      would mess up all the initialisation completed by the library.

      Edit and test.

       
  • Steve Scott

    Steve Scott - 2023-09-19

    Hey Hey Hey!
    It is working.
    Curious why the DIRs and do understand the RESET directive.
    Wll copy and paste in original learning code for verification.
    Nice to know I can use a Mikroe Click board for development with GCB!
    Thanks again Evan for shedding light.

     
    • Anobium

      Anobium - 2023-09-20

      The DIR would not cause an issue, but, the RESET would have been the issue.

      The GLCD init is:

      1. Set the Port DIR
      2. Reset the GLCD
      3. Send all the INIT commands
      4. Clear the screen

      So, the RESET would have needed all the INIT commands, again.

      If a RESET is required, sometimes I reset a GLCD to ensure the state is known, then I would call InitGLCD to correctly reset and init the GLCD.


      Insight

      To figure out what happens when you call InitGLCD can be determined by looking at the program specific CDF file.

      Searching the CDF for INITGLCD shows the following:

      Scope Line Item File
      SCRIPT/AddConstant Line 321 INITGLCD INITGLCD_ILI9341 C:\GCstudio\gcbasic\include\glcd.h

      So, InitGLCD actually is defined as InitGLCD_ILI9341 . So, the call to InitGLCD would actually call InitGLCD_ILI9341

      There is a (long) script in GLCD.H that sets up many Public methods to the specific GLCD.

       

      Last edit: Anobium 2023-09-20

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.