Menu

ILI9341 and clock speed problem

Help
2017-06-11
2017-06-17
  • stan cartwright

    stan cartwright - 2017-06-11

    Hi. I've been using ILI9341 lcd with arduino ok with GCB and the include,h fine and tried on !8f25k22 pic and works fine at 16mhz but not 32 or 64. Do I need hardwaer spi ?

    #chip 18f25k22,16
    #option explicit
    #include <glcd.h>
    ;
        #define GLCD_TYPE GLCD_TYPE_ILI9341
    
        'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
        #define GLCD_DC   portb.2 ;            ' Data command line DC
        #define GLCD_CS   portb.0 ;            ' Chip select line CS
        #define GLCD_RESET   portb.1 ;         ' Reset line
        #define GLCD_DO   portb.3 ;            ' Data out | MOSI SDI
        #define GLCD_SCK   portb.4 ;           ' Clock Line SCK
    
    ;    #define ILI9341_HardwareSPI    ' remove/comment out if you want to use software SPI.
    
     
  • Chris Roper

    Chris Roper - 2017-06-11

    You should use the Hardware whenever it is available, be it SPI, I2C or Serial.

    PIC’s are cheap and there are hundreds of them, unlike AVR’s. So if you need a particular function buy a PIC that his it in hardware. We are not stuck to what Arduino provides here.

    The Soft versions are workarounds for devices that do not have the hardware, can put considerable load on the PIC and are often written as if they are the only routine the PIC will be running. They require critical timing and often disable functions that may be needed by other devices such as timers and can be easily disrupted in turn by user programs competing for resources.

    A contentious view and it is not meant to be critical of the people who developed and tested those libraries, but I do think that the target audience should be aware that they are meant as an alternative when hardware is not available, not a replacement for existing hardware.

    Cheers
    Chris

     
  • stan cartwright

    stan cartwright - 2017-06-11

    G'day Chris. The code is from a GCB demo that can do anything I need and says supports hardware spi. The 18f25k22 is a tidy pic and I've used it with ssd1306 and the hardware pins and again nice GCB support lib. So for hardware on this device I uncomment the line for hardware and use what pins by name? please/thanks. There's only 4. Reset I'm using as normal but you can just tie the lcd reset high..works.
    I'll post about the ones like mine that use 3.3V logic but run off 5V. I used resistors instead of CD4050 as suggested link in demo cos pic got no 3.3V to drive it unlike arduino uno so simpler and works....at 16 mhz :)

     
  • stan cartwright

    stan cartwright - 2017-06-12

    Also about 3.3V logic control on these displays.What if I run the pic at 3Volt but then mess up 5v logic stuff I suppose and need step up logic.
    Another weird thing is same prog on arduino uno,change header to pic and different a to d display although same code. Pic a to d seems more sensitive and connecting to signal gen causes program reset, Touching with fingers ok but jumps to top of display ie >=5V whereas uno same prog didn't.
    A video comparison if I can't figure out by using same pc,usb and stuff,

     
  • stan cartwright

    stan cartwright - 2017-06-12

    Hi all again. I tried uncommenting the "use hardware spi" line and used what I guess used hard ware supported lines for it from microchip data pin diag. I tried tx and rx.
    Runs ok on pic and uno using software SPI. Dunno what uno harware SPI is.
    Any advice welcome for pic pin names to use for hardware spi.

    #chip 18f25k22,16
    #option explicit
    #include <glcd.h>
    ;
        #define GLCD_TYPE GLCD_TYPE_ILI9341
        'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
        #define GLCD_DC   portc.7 ;pin 18 RX1 I tried pin 17 TX1 also        ' Data command line DC
        #define GLCD_CS   portb.0 ;              ' Chip select line CS
        #define GLCD_RESET   portb.1
        #define GLCD_DO   portc.4 ;pin 15 SDI1 SDA1        ' Data out | MOSI SDI
        #define GLCD_SCK   portc.3 ;pin14 SCK1 SCL1      ' Clock Line SCK
    ;
    ;   #define ILI9341_HardwareSPI    ' remove/comment out if you want to use software SPI.
    ;
    
     
  • Anobium

    Anobium - 2017-06-13

    OK... What is the question that needs to answered?

    Are you asking where SPI works for Hardware and Software? Yes. For AVR and PIC
    The naming convention is the same for Hardware and Software SPI constants in the Great Cow BASIC libraries. They should be - if not, we need to correct.

    Please do the following review the two examples in the demo folder for this GLCD. There is one for a PIC and one AVR. Both have been tested on hardware and software SPI - if they do not work now then we need to fix it.

    I have just reviewed the ASM for mega328p and the 18f25k22 - I used hardware and software SPI. The generated ASM looks ok.

     
  • stan cartwright

    stan cartwright - 2017-06-13

    I started with the ili9341 simple demo for uno mega328 which is fine. Daft me just changed the header to pic18f25k22 an changed the ports used. That works fine to at xxxx,16 like uno running side by side.
    In my version of demos under glcd simple examples ili9341 examples use ili9340 ??
    GLCD simple example for this uses MISO which you said is not used and true, it isn't.

      #chip 16f1938,32
      #option explicit
      #config Osc = INT, VCAPEN_OFF, MCLRE_ON, PLLEN_ON, CLKOUTEN_OFF
    
        #include <glcd.h>
        #include <chipino.h>
    
        #define GLCD_TYPE GLCD_TYPE_ILI9341
    
        'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
        #define GLCD_DC       D8          ' Data command line
        #define GLCD_CS       D10         ' Chip select line
        #define GLCD_RESET    D9          ' Reset line
    
        #define GLCD_DI       D3          ' Data in | MISO
        #define GLCD_DO       D2          ' Data out | MOSI
        #define GLCD_SCK      D4          ' Clock Line
    
        #define ILI9341_HardwareSPI    ' remove/comment out if you want to use software SPI.
    

    Latest help builds available. Needs explaining as to what live help and are help files auto updated. I know sounds like I'm stupid but I said I was general Joe User.
    Ok. note above example has,as in help,no comment in #define ILI9341_HardwareSPI.
    I don't have this chip but this 18f example looks relevent.

    #chip 18f45k80, 16
    #config MCLRE=on
    #option Explicit
    #include <glcd.h>
    
    #define GLCD_TYPE GLCD_TYPE_ILI9340
    
    'Pin mappings for ILI9340
    #define GLCD_DC portc.2
    #define GLCD_CS portc.0
    #define GLCD_RESET portc.1
    
    'As we are using Harware SPI this cannot be change on this chip. This is a non-PPS chip.
    #define GLCD_DI portc.4
    #define GLCD_DO portc.5
    #define GLCD_SCK portc.3
    #define ILI9340_hardwarespi
    

    I want to convert this to 18f25k22 so check data sheet for 18f45k80 and see what it's using and apply to my pic...Yes? gonna try anyway.
    and ps. does everyone with .97 have same demo and help as me.I noticed the mega328 ili9341 has been updated but not others so was that just a link you sent me Evan? Was it rc stuff?

     

    Last edit: stan cartwright 2017-06-13
  • Anobium

    Anobium - 2017-06-13

    I do not understand the first paragraph - but, generally you should stick with the defined constants. Constants and ports not used may cause a few bytes to be used up but an overhead that is acceptable.

    'In my version of demos under glcd simple examples ili9341 examples use ili9340 ??' If this is in an RC release then please post your recommended corrections to the Developer forum. All recommended correction and changes are gladly accepted to improve the quality of the demos.

    Regarding Help file improvements. Please take a copy and edit. All improvements are gladly accepted. We have hundreds of Help pages so any improvements are really welcome.

    I think the answer is yes to your last paragraph regarding changing the port assignments.

    Re the demos. Everyone within a release has the same demos. Demos are updated and enhanced all the time. You have v0.97.02 RC 3 and the demos have therefore been updated. Please post question re the RC build to the Developer Forum.

     
  • stan cartwright

    stan cartwright - 2017-06-13

    This with comment removed ie hardware spi ..Dim works.

    #chip 18f25k22,16
    #option explicit
    #include <glcd.h>
    ;
        #define GLCD_TYPE GLCD_TYPE_ILI9341
        'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
        #define GLCD_DC   portc.7 ;pin 18 RX1         ' Data command line DC
        #define GLCD_CS   portb.0 ;              ' Chip select line CS
        #define GLCD_RESET   portb.1
        #define GLCD_DO   portc.4 ;pin 15 SDI1 SDA1        ' Data out | MOSI SDI
        #define GLCD_SCK   portc.3 ;pin14 SCK1 SCL1      ' Clock Line SCK
    ;
    ;   #define ILI9341_HardwareSPI    ' remove/comment out if you want to use software SPI.
    

    So what should work? I'm just messin arround with this display and it's just the hardware spi that's a prob,the rest is very good. Would others have sorted this and I'm missing summat?
    Is this nothing to do with gcb and see the data sheet stuff?

     
  • Anobium

    Anobium - 2017-06-13

    I do not uunderstand the posting. I am trying to Help. A conversation on Google Chat would help. You know where I am.

    First sentence. What comment? What Dim? are you referring to?

    Last paragraph. First sentence. What should work? I cannot tell from the information provided.

    Last paragraph. Second half of the first sentence.Are you saying that SPI is not working? are those ports valid with respect to the specific chip? Have you confirmed?

    Last paragraph. Last sentence.'Is this nothing to do with gcb and see the data sheet stuff?' Is this a statement or a question?

     
  • stan cartwright

    stan cartwright - 2017-06-13

    I don't see posting in developers is necessary. The ili9341 runs off 4 wires with software spi.Forget reset and miso-sdi-di
    sdo,sck -- dc and cs
    ds and cs can be anything or ds hardeware
    sdo,sck hardware pins

     

    Last edit: stan cartwright 2017-06-13
  • Anobium

    Anobium - 2017-06-13

    If your question is about the Demos in an RC release. Which your posting https://sourceforge.net/p/gcbasic/discussion/579126/thread/6c21227f/#3d20 seemed to be about then that goes in the Dev forum. If you want to improve the Help then Dev forum is a good place for that as you have an RC version. Otherwise, this is the correct forum for Help.

    I am trying to help. What does 'cs is sdo sdi' mean?

     
  • stan cartwright

    stan cartwright - 2017-06-13

    With the hardware spi define line uncommented the ili9341 demo works aok with uno and pi with any ports.
    I want to use hardware spi so I uncomment hardware spi line and use pins that are hardware spi...which I think are the correct ones and the screen is white.
    I will try with uno. Uno has scl,sda,tx,rx marked on the board so are these pic equivelents. Do I need to use tx or rx for dc line?..guessing cs is any port...in a teapot...avoiding storm.
    Confusing for beginners is different names for the same thing as in the pin names mosi di sdi.
    I think help is the correct part of the forum for this and could be resolved with try these pins but that I think is some thing I should sort myself and I have tried and can't get it working....the reason it don't work is..? I dunno. I also dunno why software spi works at 16 and not at 32 or 64 clock.
    ps I appreciate your help and time...and due credit for the others involved in developing gcb.

     
  • Anobium

    Anobium - 2017-06-13

    working code for the ILI9341. I took the 18f demo, changed the SPI only. Compiled - seems to work,

    '
    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program is a simple GLCD demonstration of the ILI9341 GLCD capabilities.
    '''It is a nice graphical LCD, suitable for a lot of various projects.
    '''This program draws lines, boxes, circles and prints strings and numbers.
    '''The GLCD is connected to the microprocessor as shown in the hardware section of this code.
    ''':
    '''This has been tested using the hardware SPI option.
    ''':
    ''':
    '''@author  EvanV
    '''@licence GPL
    '''@version 1.0
    '''@date    08/11/16
    '''********************************************************************************
    
      'Chip Settings
    #chip 18f26k22, 16
    #config MCLRE=on
    #option Explicit
    #include <glcd.h>
    
    #define GLCD_TYPE GLCD_TYPE_ILI9341
    
    'Pin mappings for ILI9341
    #define GLCD_DC portc.2
    #define GLCD_CS portc.0
    #define GLCD_RESET portc.1
    
    'As we are using Harware SPI this cannot be change on this chip. This is a non-PPS chip.
    #define GLCD_DI portc.4
    #define GLCD_DO portc.5
    #define GLCD_SCK portc.3
    #define ILI9341_hardwarespi
    
    
    
    dir porta.3 out
    set porta.3 off 'ttf backlight pwr set on (pnp)
    
    
    glcdrotate(landscape_rev)
    
    
    glcdcls
    glcdprint(100,100,"Great Cow BASIC",ili9341_white)
    glcdprint(100,124, ChipNameStr )
    glcdprint(100,200,"Hello Stan",ili9341_white)
    
    
    do
    dir porta.0 out
    porta.0 = !porta.0
    wait 100 ms
    loop
    sleep
    

    Edit as I posted the ILI9340 code. This is the working code for the ILI9341 tested on an 18f26k22.

    Question/Statement | Response
    ---------- | ---------- | ------
    With the hardware spi define line uncommented the ili9341 demo works aok with uno and pi with any ports. | I would advice to start with the 18f demonstration.
    I want to use hardware spi so I uncomment hardware spi line and use pins that are hardware spi...which I think are the correct ones and the screen is white.| You need to look at the datasheet for SPI or SPI1. Where did you get the SPI ports from ? I got mine from page 20 of the datasheet.
    I will try with uno. Uno has scl,sda,tx,rx marked on the board so are these pic equivelents. Do I need to use tx or rx for dc line?..guessing cs is any port...in a teapot...avoiding storm.|Not sure. You want an 18f so I would focus on this architecture.
    Confusing for beginners is different names for the same thing as in the pin names mosi di sdi.|Yes. This is hard. Hence, forum exist to share.
    I think help is the correct part of the forum for this and could be resolved with try these pins but that I think is some thing I should sort myself and I have tried and can't get it working....the reason it don't work is..? I dunno. |OK
    I also dunno why software spi works at 16 and not at 32 or 64 clock|What chip?
    ps I appreciate your help and time...and due credit for the others involved in developing gcb.|Pleasure

     

    Last edit: Anobium 2017-06-13
  • Anobium

    Anobium - 2017-06-13

     
  • stan cartwright

    stan cartwright - 2017-06-13

    What surprises when I try getting touch control working? Only 4 lines,what could be simpler?...knitting probably...and that's hard if I remember!

     
    • Chris Roper

      Chris Roper - 2017-06-13

      Well the concept of programming and the punch cards did originate with weaving looms and Knitting machines so one could argue that knitting is harder :)

       
  • stan cartwright

    stan cartwright - 2017-06-14

    I was on about difficult like juggling and how long to sort code. :) My poor analogy.
    Not every thing is on a plate yet but GCB is looking better weekly.
    This lcd hasn't got touch screen support so a bit of work is needed needed.
    I hate data sheets but there's a gcb touch example I can use and lib but not peasy for moi.
    Interesting trying though.

     
  • stan cartwright

    stan cartwright - 2017-06-17

    OK. working fine now. My fault for not seeing previous example post. Yes, I see now the hardware spi pins needed on this pic. Works faster visually than software that can be any pins. I should have learnt this from using other displays and same hardware pins. These cheap lcds are fun to use with gcb just make sure it's 5V compatable...less extra wiring than a 3.3V one.
    After thought - Arduino boards are not representative of the microcontroller. The data sheet is true although not bed time reading.
    mega328p GLCD_DC portb.2 is called SS in data sheet...It's confusing but with portb.3 and 5 hardware spi works fine on my 328 uno. Isn't hardware spi so handy when you know what it does like other hardware features...hpwm is also very simple...not

     

    Last edit: stan cartwright 2017-06-18

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.