Menu

Hardware SPI

Help
2021-02-02
2021-02-02
  • David Stephenson

    I've been using SPI for some time. Generally I just cut and paste from an old program when I'm setting up the SPI mode. This time I decided to look at the help files...
    1. The SPI initialization seems to have got much more complex.
    2. I started to worry that I was actually using software SPI, but a quick look at the ASM file showed that I was indeed using HWSPI.
    Anyway here is the code I've been using for at least a decade - should I make alterations? It seems to still work.
    (Ok the PPS definitions are much more recent)

    unlockpps
                'Module: MSSP1 SPI interface
                SSP1DATPPS = 0x000C    'RB4 > SDI1
                RC2PPS = 0x0019    'SDO1 > RC2
                SSP1CLKPPS = 0x000E    'RB6 > SCL1
                RB6PPS = 0x0018    'SCL1 > RB6 (bi-directional)          
    lockpps
    dir portc.1 out 'chip select
    set portc.1 on 'unselect
    dir portc.2 out 'sdo
    dir portb.4 in 'sdi
    dir portb.6 out 'clk
    SPIMode Masterfast,3 'initialize spi
    
     
    • Anobium

      Anobium - 2021-02-02

      Looks ok but SPI is specific to the chip. PPS or not, port assignment etc.
      The setup in the demos is to show how to use software SPI and hardware together, using a constant to control PPS (if required).

      Your code above looks ok for your solution and may work on a different chip. There is no general case to set up SPI.

      PPSTool should be used to create a specific setup for a specific chip.

       
  • stan cartwright

    stan cartwright - 2021-02-02

    I also cut and paste working code like spi setup.
    I use avr and pics that are pre pps ie hspi pins are the ones you get in the data sheet.
    The hspi help is now a timing signal demo/explanation.. but over my head.
    I have two il19341 touch glcd .One is running hardware spi on a mega328 ok,
    the other is the same program but and glcd but uses a LGT328 and testing Anobium's
    demos for the lgt328 and ili9341 only got it working with software spi.
    software spi is visually on a glcd 4 times slower so setting up touch panels etc. would
    be too slow.
    I don't think hspi for ili9341 touch on lgt328 has been sorted yet and if Anobium can't sort it then what chance do I have?

    ps when I looked up hwspi it sat the chip has hardware that when it receives instructions it carries them out and lets the program carry on doing other code ??? does it?

     

    Last edit: stan cartwright 2021-02-02
    • Anobium

      Anobium - 2021-02-02

      SPI touch works on the LGT. The hardware SPI on the LHT is too fast for the Touch, so, you have to use Software SPI... which means the GLCD runs slower.

      Hardware SPI on LGT to GLCD is very fast.

      So, the answer. Find a touch IC that can work at the faster frequency.

      The issue is not the library but the touch IC.

       
  • David Stephenson

    Maybe I was being overcritical it's just the SPI overview seems to confuse things.
    The rest of the help is very useful, I have found that I should have been using mode 0 and I had it set to mode 3. Even stranger I get communication in both modes (I am using a RFM69W module).

     
  • Chris Roper

    Chris Roper - 2021-02-02

    Help is not cast in stone, it is a living document.

    The Help that is installed with GCBASIC is the best interpretation of the Microchip Datasheet for the device, or devices, that the Help compiler had at hand to test with.

    The results may vary between devices and/or device families, even though GCBASIC strives to ensure that that is not the case.

    The Help on GIT Hub may be slightly more up to date than that installed with your copy of GCBASIC but it is not necessarily authenticated by other users on other devices.

    One of the best contributions a user can make to GCBASIC is to publish any corrections or mistakes that they find in the existing Help.
    If there is no entry, any notes that you take whilst experimenting can be a great aid to future users and form a stub of a Help Entry.

    Simple example Code to augment the help would also be appreciated.

    So if it doesn't work as expected don't assume that you, or the help, were wrong.
    Rather first make sure that your Device is supported and that it has no special requirements.
    If it has make some notes and if you overcome the problem, update the Help.

     

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.