Menu

Hardware SPI with mega1284p and an ILI9341

Help
2019-11-03
2019-11-04
  • Manfred Weichselbaum

    Resolved


    Hi Guys,
    it's the first time I'm asking you for help. Please excuse my english, but my native language is german.

    I have a problem with a mega1284p and an ILI9341 display.
    My system:
    Linux Mint 19.2 Cinnamon, kernel 4.15.0-66 generic.
    FreeBASIC 1.07.1-ubuntu-4.18-x86_64
    GreatCowBASIC UNIX v0_98_06

    The chip is clocked externally at 16MHz.

    ' --- CHIP CONFIGURATION
        #chip mega1284p, 16
        #option explicit
    
    ' --- INCLUDE FILES
        #include <glcd.h>
    
    ' --- GLCD SETTINGS
        #define GLCD_TYPE   GLCD_TYPE_ILI9341
        #define GLCD_WIDTH  320
        #define GLCD_HEIGHT 240
        #define GLCD_EXTENDEDFONTSET1
    
        'Define ports for the ILI9341 display
        #define GLCD_CS         PORTD.6
        #define GLCD_RESET      PORTD.5
        #define GLCD_DC         PORTD.4
        #define GLCD_DO         PORTB.5
        #define GLCD_SCK        PORTB.7
        '#define ILI9341_HardwareSPI
    
     --- FLASHING LED
        dir PORTD.7 out
    

    My problem:
    Software SPI works.
    When I use "#define ILI9341_HardwareSPI" the chip gets stuck. The display stays white and a control LED that flashes in software SPI mode remains dark.

    I searched the header files "glcd.h" and "ili9341.h". In the file ili9341.h I found the following passage:

    #ifdef AVR
        do
            SPDR = ILI9341SendWord_h
        Loop While SPSR.WCOL
    
        'Read buffer
        Same for master and slave
        Wait While SPSR.SPIF = Off
        do
            SPDR = ILI9341SendWord
        Loop While SPSR.WCOL
    
        'Read buffer
        Same for master and slave
        Wait While SPSR.SPIF = Off
    #endif
    

    My questions:
    Where is AVR defined? I did that in my test program as part of the ILI9341 definition, but without success.
    Can it be that hardware SPI is not supported in the interaction mega1284p and ILI9341?
    Am I doing something wrong?

    Does somebody has any idea?
    Thank you very much

     

    Last edit: Anobium 2019-11-04
    • Anobium

      Anobium - 2019-11-04

      Hello Manfred,

      Where is AVR defined? I did that in my test program as part of the ILI9341 definition, but without success.

      AVR is a compiler constant. It is determined by the chip you have stated.


      Can it be that hardware SPI is not supported in the interaction mega1284p and ILI9341?
      Am I doing something wrong?

      As we know the software SPI works for you. We need to valide that harware SPI works on this chip. So, rather than have me struggle to recreate you code. Please post source code. Then, we can look at the generated ASM to determine if hardware SPI exists.


      Does somebody has any idea?

      Yes.

      Evan

       

      Last edit: Anobium 2019-11-04
      • Manfred Weichselbaum

        Hello Anobium,
        attached the source code of the test program.

         
        • Anobium

          Anobium - 2019-11-04

          Manfred,

          You pin selection is incorrect. Whilst this WILL work for SW SPI. The HW SPI pinout needs to conform the datasheet.

          SW SPI as you have it:

          'Define ports for the ILI9341 display
          #define GLCD_CS         PORTD.6
          #define GLCD_RESET      PORTD.5
          #define GLCD_DC         PORTD.4
          #define GLCD_DO         PORTB.5
          #define GLCD_SCK        PORTB.7
          

          HW SPI - see page 2 of the datasheet

              'Define ports for the ILI9341 display
              #define GLCD_CS         PORTD.4      'Was incorrect .This needs to be the SS slave select line
              #define GLCD_RESET      PORTD.5      'can be any port .. therefore, is OK
              #define GLCD_DC         PORTx.y      'can be any port .. therefore, is OK
              #define GLCD_DO         PORTB.5      'This is valid.
              #define GLCD_SCK        PORTB.7      'This is valid.
          

          So, you need to resolve the CS (SS) port and move the DC port.

          Something like

              'Define ports for the ILI9341 display
              #define GLCD_CS         PORTD.4    'corrected
              #define GLCD_RESET      PORTD.5  
              #define GLCD_DC         PORTB.3    'corrected  
              #define GLCD_DO         PORTB.5  
              #define GLCD_SCK        PORTB.7  
          

          I cannot test etc but I think my recommendations are valid.

           
          • Manfred Weichselbaum

            Ah, I thought CS can be chosen by software. That was a mistake. It is running now.
            Thanks alot

             
  • stan cartwright

    stan cartwright - 2019-11-03

    I use-

    #chip mega328p,16
    #include <glcd.h>
    #option explicit
    ;--------------
    #define GLCD_TYPE GLCD_TYPE_ILI9341
    
    #define GLCD_DC      portb.0 ;   DIGITAL_8           ' Data command line
    #define GLCD_CS      portb.2 ;   DIGITAL_10          ' Chip select line
    #define GLCD_RESET   portb.1 ;   DIGITAL_9           ' Reset line
    #define GLCD_DI      portb.4 ;   DIGITAL_12          ' Data in | MISO    - Not used therefore not really required
    #define GLCD_DO      portb.3 ;   DIGITAL_11          ' Data out | MOSI
    #define GLCD_SCK     portb.5 ;   DIGITAL_13          ' Clock Line
    
    #define ILI9341_HardwareSPI    ' remove/comment out if you want to use software SPI.
    #define GLCD_EXTENDEDFONTSET1
    

    For hardware spi use pins dedicated to mosi and clock. maybe you have, I have not looked at mega1284p pins.

     
  • stan cartwright

    stan cartwright - 2019-11-03

    I can only say that the ili9341 include has been updated in latest gcb win version.

     
    • Manfred Weichselbaum

      Hello Stan,
      Thank you for your intention to help me. GLCD_SCK and GLCD_SDO are connected to PORTD.5 and PORTD.7 according to the datasheet. It corresponds to the connections in your picture. The include file ili9341.h is the current version. It's an interesting phenomenon, in hardware SPI mode the chip hangs. For the moment I give up, I have no idea anymore. Maybe the chip is broken.
      Thanks Manfred

       
  • stan cartwright

    stan cartwright - 2019-11-03

    @Manfred
    Your system is....My system:
    Linux Mint 19.2 Cinnamon, kernel 4.15.0-66 generic.
    FreeBASIC 1.07.1-ubuntu-4.18-x86_64
    GreatCowBASIC UNIX v0_98_06
    Groovy. I am trying mint 19.2 and have complied freebasic and used freebasic to compile great cow basic but do not know how to set up geany to use freebasic or great cow basic.
    So I use win 7...and it all works.

     
  • stan cartwright

    stan cartwright - 2019-11-04

    Thanks Manfred. I had seen it https://sourceforge.net/p/gcbasic/discussion/579125/thread/2447715df2/?limit=25&page=0
    Looks too complicated to me. I am a new linux user. I have only used linux on a rasperry pi because I have to.
    I like mint 19.2 because it is like using win 10 but runs 10 times faster on the same pc and hdd. Dual boot grub.

    I did not think cs or dc were hardware spi ports for ili9341. My error,sorry.

     
    • Manfred Weichselbaum

      I also thought that only CLK and MOSI are hardware ports. But it works now.
      Have a nice day.

       
      • stan cartwright

        stan cartwright - 2019-11-04

        I am glad it is working. If you like you can experiment with the ili9341 include......for your own entertainment only. You can send whole bytes ie 8 pixels, different colours from gcb code easy.
        Also solve wrap around if co-ordinate goes off screen. I wanted to write asteroids game.

         

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.