Today 00:49
Forum: Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C / Master and Slave modes
Starter: RGV250
Views: 0
Replies: 0
Go to last post By: RayEllam
Today 00:32
Forum: Proton 24
Starter: RayEllam
Views: 1150
Replies: 8
Yesterday 15:42
Forum: Proton 24
Starter: matty
Views: 0
Replies: 3
+ Reply to Thread
Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 54

Thread: SPI GLCD Help needed1826 days old

  1. #41
    Junior Member starwars's Avatar
    Join Date
    Feb 2016
    Posts
    24
    Thumbs Up
    Received: 0
    Given: 19
    Total Downloaded
    0

    0 Not allowed!

    Default Re: SPI GLCD Help needed

    Hi Barak

    Thank you for your reply.
    I'm using a PIC18F26K22 with the EADOGM128 module. I've tried the wiki code, and the other code that is on the forum. One code that I've used successfully is '* Name : EADOG 128x64.BAS * '* Author : [JD SMITH] * But this doesn't do fonts or graphics and is a bit rudimentary. I was really looking forward to using your code. I had also tried the the MSSP2 version of the code that was available but I'm not able to locate it right now, and will re-scan the forum.
    Many thanks for your help.

    Harry

  2. #42
    Senior Member barak's Avatar
    Join Date
    Apr 2008
    Posts
    739
    Thumbs Up
    Received: 47
    Given: 11
    Total Downloaded
    548.98 MB

    1 Not allowed!

    Default Re: SPI GLCD Help needed

    Quote Originally Posted by starwars View Post
    Hi Barak

    I've used this file, thank you for the help.

    But, it doesn't seem to work for me.
    I've used these settings:
    '---[SPI/GLCD interface Defines]-------------
    Symbol CS1B = PORTA.5 ' CS1B is the EADOGM128-6 "Chip Select Not" pin
    High CS1B ' make sure it does't get any
    Symbol A0 = PORTA.2 ' LCD A0: 0 = Command, 1 = data
    Symbol GLCD_RST = PORTA.3 ' Reset Active low
    Low GLCD_RST ' keep in reset
    The SCL wired to RB1
    and SDO goes to RB3

    What am I missing?

    Thanks
    Harry
    the code at http://www.protonbasic.co.uk/attachm...5&d=1476265849 is for PIC18F46K22 but it is using the MSSP1 module for SPI. Therefore you must connect SDO1 on RC5 and SCK1 on RC3. Read the datasheet for more details.

  3. #43
    Junior Member starwars's Avatar
    Join Date
    Feb 2016
    Posts
    24
    Thumbs Up
    Received: 0
    Given: 19
    Total Downloaded
    0

    0 Not allowed!

    Default Re: SPI GLCD Help needed

    Hi Barak
    Unfortunately, the board I have has an SDCard using those very same pins and I can't resolder those pins
    Any way to adapt the code for using MSSP2?

    Thank you for your time

    Harry

  4. #44
    Senior Member barak's Avatar
    Join Date
    Apr 2008
    Posts
    739
    Thumbs Up
    Received: 47
    Given: 11
    Total Downloaded
    548.98 MB

    1 Not allowed!

    Default Re: SPI GLCD Help needed

    Quote Originally Posted by starwars View Post
    Hi Barak
    Unfortunately, the board I have has an SDCard using those very same pins and I can't resolder those pins
    Any way to adapt the code for using MSSP2?

    If the SD card is Using SPI, you can use the same MOSI and SCK for both the SDCard and the LCD. Unless you pull down the Chip Select (CS1B on the LCD), the device will ignore the communications. Even if you use it on I2C, you should be able to configure it as SPI for the LCD when you need it. If you want to use SSP2 for the LCD, change in the file 'PIC18F4XK22_Setup.Inc' :
    Code:
    '-----[SPI/LCD Interface setup]-----
    SPI_Con:      
        SSP1CON1 = 000001            ' configure SPI Master, FOSC/16 so SCL is 1MHz 
        Symbol SSP1EN  = SSP1CON1.5     ' SSP Enable bit
        Symbol CKP1    = SSP1CON1.4     ' Clock Polarity Select
        Symbol SMP1    = SSP1STAT.7     ' Data input sample bit
        Symbol CKE1    = SSP1STAT.6     ' Clock Edge Select bit
        Symbol BF1     = SSP1STAT.0     ' buffer full status bit 1 = buffer full
        Symbol SSP1IF  = PIR1.3         ' interrupt flag - last bit set
    to:
    Code:
    '-----[SPI/LCD Interface setup]-----
    SPI_Con:      
        SSP1CON2 = 000001            ' configure SPI Master, FOSC/16 so SCL is 1MHz 
        Symbol SSP2EN  = SSP2CON1.5     ' SSP Enable bit
        Symbol CKP2    = SSP2CON1.4     ' Clock Polarity Select
        Symbol SMP2    = SSP2STAT.7     ' Data input sample bit
        Symbol CKE2    = SSP2STAT.6     ' Clock Edge Select bit
        Symbol BF2     = SSP2STAT.0     ' buffer full status bit 1 = buffer full
        Symbol SSP2IF  = PIR3.7         ' interrupt flag - last bit set
    Then change the everything in the code to SSP2, you will get compile errors that will guide to to the places that need changed.
    SDO2 should be on RD4 and SCK on RD0.

  5. #45
    Junior Member starwars's Avatar
    Join Date
    Feb 2016
    Posts
    24
    Thumbs Up
    Received: 0
    Given: 19
    Total Downloaded
    0

    0 Not allowed!

    Unhappy Re: SPI GLCD Help needed

    Hi Barak
    I'md really sorry to pester you about this and you've also helped with not only writing the whole library and also providing me an MSSP2 solution below which I am grateful for. But that did not work too. I understand that you have this code for the 18F46K22 while I'm using the 18F26K22. I've reconfigured the pins to use all the RB ports and have wired it correctly. I'm including the relevant wiring between ports and pins.

    RST --------> PortB.5
    CE (CS1B) -> Port B.0
    CLK --------> PortB.1
    SI ----------> PortB.3
    LED --------> PortB.2
    A0 ---------> PortB.4
    The relevant section of the code is
    Code:
     '****************************************************************
    '*  Name    : PIC18F4XK22_Setup.inc                             *
    '*  Author  : Barak Dar                                         *
    '*  Notice  :                                                   *
    '*          : All Rights Reserved                               *
    '*  Date    : 05/03/2012                                        *
    '*  Version : 1.0.0                                             *
    '*  Notes   : Device setup for 18F45K22                         *
    '*          :                                                   *
    '****************************************************************
    
    Device = 18F26K22
    
    Config_Start
       FOSC = INTIO67 ; not HS oscillator (medium power 4-16 MHz)
       PLLCFG = Off ; Oscillator used directly
       PRICLKEN = OFF ; Primary clock can be disabled by software
       FCMEN = On ; Fail-Safe Clock Monitor enabled
       IESO = On ; Oscillator Switchover mode enabled
       PWRTEN = On ; Power up timer enabled
       BOREN = NOSLP ; Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
       BORV = 190 ; VBOR set to 1.90 V nominal
       WDTEN = SWON ; WDT is controlled by SWDTEN bit of the WDTCON register
       WDTPS = 128 ; 1:128
       CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1
       PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset
       CCP3MX = PORTB5 ; P3A/CCP3 input/output is mulitplexed with RE0
       HFOFST = On ; HFINTOSC output and ready status are not delayed by the oscillator stable status
       T3CMX = PORTC0 ; T3CKI is on RC0
       P2BMX = PORTC0 ; P2B is on RC0
       MCLRE = EXTMCLR ; MCLR pin enabled, RE3 input pin disabled
       STVREN = On ; Stack full/underflow will cause Reset
       LVP = OFF ; Single-Supply ICSP disabled
       XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
       Debug = OFF ; Disabled
       Cp0 = OFF ; Block 0 (000800-001FFFh) code-protected
       CP1 = OFF ; Block 1 (002000-003FFFh) code-protected
       CP2 = OFF ; Block 2 (004000-005FFFh) code-protected
       CP3 = OFF ; Block 3 (006000-007FFFh) code-protected
       CPB = OFF ; Boot block (000000-0007FFh) code-protected
       CPD = OFF ; Data EEPROM not code-protected
       WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected
       WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected
       WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected
       WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected
       WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
       WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
       WRTD = OFF ; Data EEPROM not write-protected
       EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
       EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
       EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
       EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
       EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    
    Optimiser_Level = 3
    
    Xtal = 16                           ' Declare Fosc 
    
    Declare Stack_Size = 8                
    
    '---[OSC config]---------------------        
        OSCCON  = %01110000             ' IRCF = 111 = internal osc 16MHz; SCS = 00 Primary OSC from CONFIG1H
        OSCCON2 = %00000100             ' PRISD OSC drive circuit on
        OSCTUNE = %00000000             ' TUN = 000000 = Osc module runs at factory calibration
        Symbol PRISD = OSCCON2.2        ' OSC drive circuit control
        Symbol PLLEN = OSCTUNE.6        ' Enable/disable PLL
    
    '---[Ports Config]-------------------
    Port_Con:
        '        |76543210|
        ANSELA = %00000000               
        ANSELB = %00000000                     
        ANSELC = %00000000
       ' ANSELD = %00000000
        'ANSELE = %00000000                     
        TRISA  = %00000000              
        TRISB  = %00000000              ' PORTB all inputs but leave PORTB.7 as output for SW UART TX      
        TRISC  = %01010000              ' Set RC.4 Input For MISO, RC.6 TX1, all other outputs          
       ' TRISD  = %00000000              
        'TRISE  = %00000000              
    
    
    '---[Weak Pullups Config]------------    
    'Pullup_Con:
    '    '      |76543210|
    '    WPUB = %00111111                ' week pull-up selected for Switches and IRQ from SPI device on RB.0 
    '    Symbol RBPU = INTCON2.7         ' PORTB Pull-up Enable/disable
    '    RBPU = 0                        ' weak pullup on portB 
    
    '-----[SPI/LCD Interface setup]-----
    'SPI_Con:                       ' MSSP1
    '              '|76543210|
    '    SSP1CON1 = %00000001            ' configure SPI Master, FOSC/16 so SCL is 1MHz 
    '    Symbol SSP1EN  = SSP1CON1.5     ' SSP Enable bit
    '    Symbol CKP1    = SSP1CON1.4     ' Clock Polarity Select
    '    Symbol SMP1    = SSP1STAT.7     ' Data input sample bit
    '    Symbol CKE1    = SSP1STAT.6     ' Clock Edge Select bit
    '    Symbol BF1     = SSP1STAT.0     ' buffer full status bit 1 = buffer full
    '    Symbol SSP1IF  = PIR1.3         ' interrupt flag - last bit set   
        
        SPI_Con:      
        SSP2CON1 = %00000001               ' configure SPI Master, FOSC/16 so SCL is 1MHz 
        Symbol SSP2EN  = SSP2CON1.5     ' SSP Enable bit
        Symbol CKP2    = SSP2CON1.4     ' Clock Polarity Select
        Symbol SMP2    = SSP2STAT.7     ' Data input sample bit
        Symbol CKE2    = SSP2STAT.6     ' Clock Edge Select bit
        Symbol BF2     = SSP2STAT.0     ' buffer full status bit 1 = buffer full
        Symbol SSP2IF  = PIR3.7         ' interrupt flag - last bit set
    
    PinAssign:
    '    Symbol SW1      = PORTB.1       ' keypad [1]      
    '    Symbol SW2      = PORTB.2       ' keypad [2]
    '    Symbol SW3      = PORTB.3       ' keypad [3] 
    '    Symbol SW4      = PORTB.4       ' keypad [4]
    '    Symbol SW5      = PORTB.5       ' keypad [5]     
            
        Symbol LEDs     = PORTA.6        ' all the leds
    '    Symbol LED_1    = PORTE.0       ' LED D2 - right side
    '    Symbol LED_2    = PORTE.1       ' LED D3 - left side
    '    Symbol LED_3    = PORTE.2       ' LED D4 - center bottom
    '    Symbol TP2      = PORTE.2       ' ***OFD*** test point for scope
    Code:
        '---intialize the SPI in Mode 0-----------------
        SMP2   = 0                                      ' Data input sampled at middle of data output time
        CKE2   = 0'1                                      ' CPHA - transmit on falling edge active to idle 
        CKP2   = 1'0                                      ' CPOL - idle state is low level
        SSP2EN = 1                                      ' Enable SPI
    Code:
        '---[SPI/GLCD interface Defines]-------------    
        Symbol CS1B     = PORTB.0                   ' CS1B is the EADOGM128-6 "Chip Select Not" pin  
        Low CS1B                                   ' make sure it does't get any    
        Symbol A0       = PORTB.4                   ' LCD A0: 0 = Command, 1 = data              
        Symbol GLCD_RST = PORTB.5                   ' Reset Active low
        Low GLCD_RST                                ' keep in reset
        
        
        Symbol SI       = PORTB.3             'These lines are just in case, I have removed them but still doesn't work
        Symbol SK       = PORTB.1
    I really don't know all the register settings correctly, but I've tried various things, such as setting the BAUD and FOSC etc. But, I think I'm missing something.

    Once again many thanks for going through this, I hope I am able to make this work on the 18LF26K22 or will have to wait for the 18F46K22 chip to arrive.

    Harry

  6. #46
    Senior Member barak's Avatar
    Join Date
    Apr 2008
    Posts
    739
    Thumbs Up
    Received: 47
    Given: 11
    Total Downloaded
    548.98 MB

    1 Not allowed!

    Default Re: SPI GLCD Help needed

    Sorry, I thought you are using 46K22. The 81F26K22 is OK and the code should work.
    So on the 26K22 you have the LCD connected to MSSP2.
    I noticed you have a keypad on port B but also using it for the LCD, I would remove the keypad related code until you figure out the LCD.
    Are you using MSSP2 to send data to the LCD in sub 'SPI_GLOBAL'?
    Did you make all the changes in 'ST7565_DEF.Inc'?
    If all the above is OK, I recommend checking the SPI interface with a scope or logic analyzer. Send one byte in a loop and see that it actually works. The clock should be 1MHz.
    Last edited by barak; 14th January 2017 at 15:37.

  7. #47
    Junior Member starwars's Avatar
    Join Date
    Feb 2016
    Posts
    24
    Thumbs Up
    Received: 0
    Given: 19
    Total Downloaded
    0

    0 Not allowed!

    Default Re: SPI GLCD Help needed

    Thanks Barak for the quick reply
    The keypad code has been commented out.
    Are you using MSSP2 to send data to the LCD in sub 'SPI_GLOBAL'?
    Not sure what I need to do here, but I've not modified your original code except what you mentioned changes for MSSP2


    Did you make all the changes in 'ST7565_DEF.Inc'?
    I have made the following changes in the code in the .DEF file

    Code:
    '---[SPI/GLCD interface Defines]-------------    
        Symbol CS1B     = PORTB.0                  ' CS1B is the EADOGM128-6 "Chip Select Not" pin  
        Low CS1B                                            ' make sure it does't get any    
        Symbol A0       = PORTB.4                    ' LCD A0: 0 = Command, 1 = data              
        Symbol GLCD_RST = PORTB.5              ' Reset Active low
        Low GLCD_RST                                    ' keep in reset
        Symbol SI       = PORTB.3
        Symbol SK       = PORTB.1
    I recommend checking the SPI interface with a scope or logic analyzer. Send one byte in a loop and see that it actually works. The clock should be 1MHz.
    Sorry, I don't have a scope or logic analyser, will try to get a logic analyser from the market

    But, thanks for all your help so far, I really appreciate it.

    Kind regards

    Harry

  8. #48
    Senior Member barak's Avatar
    Join Date
    Apr 2008
    Posts
    739
    Thumbs Up
    Received: 47
    Given: 11
    Total Downloaded
    548.98 MB

    1 Not allowed!

    Default Re: SPI GLCD Help needed

    Quote Originally Posted by starwars View Post
    Code:
    '---[SPI/GLCD interface Defines]-------------    
        Symbol SI       = PORTB.3
        Symbol SK       = PORTB.1
    Why did you define SI and SK? If using the MSSP it is not needed.
    The SPI sub should be changed to send the buffer of MSSP2:
    Code:
    SPI_GLOBAL:                                         ' generic SPI sub                 
        Pop SSP2BUF                                     ' trasmit a byte from stack
        While SSP2IF = 0 : Wend                         ' wait for end of transaction
        SSP2IF = 0                                      ' clear the SSP flag
        SPI_BYTE_IN = SSP2BUF                           ' nothing to do with the LCD use to read from other slaves
        Return

  9. #49
    Junior Member starwars's Avatar
    Join Date
    Feb 2016
    Posts
    24
    Thumbs Up
    Received: 0
    Given: 19
    Total Downloaded
    0

    0 Not allowed!

    Default Re: SPI GLCD Help needed

    Hi Barak

    Thank you so much, there was a small mistake that I made in the code
    Code:
    Pop SSP2BUF
    was missing from my side. it was
    Code:
    Pop SSPBUF
    You just made my weekend!!
    I can now learn the code and make the display that I was waiting for a long time!!!!

    Cheers

    Harry

  10. #50
    Senior Member barak's Avatar
    Join Date
    Apr 2008
    Posts
    739
    Thumbs Up
    Received: 47
    Given: 11
    Total Downloaded
    548.98 MB

    1 Not allowed!

    Default Re: SPI GLCD Help needed

    My fault. I did some tests with 18F45K20 so I commented the original sub (see in code below) and forgot to change it to 'Pop SSP1BUF' . The compiler is forgiving and permits 'SSPBUF' although 18FXXK22 does not have such register.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. SPI - (Can't belive a search on SPI yields no results?)
    By Peter Truman in forum Proton Plus Compiler v3
    Replies: 12
    Last Post: 30th September 2012, 10:12
  2. Replies: 7
    Last Post: 21st June 2012, 16:43
  3. Cheap GLCD needed
    By Tim in forum The Lounge
    Replies: 15
    Last Post: 8th September 2009, 18:10
  4. Another connector needed.
    By See_Mos in forum Wanted and For Sale
    Replies: 0
    Last Post: 17th July 2009, 09:01
  5. advice needed
    By C_Moore in forum The Lounge
    Replies: 7
    Last Post: 4th July 2006, 15:48

Members who have read this thread : 104

Actions :  (Set Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts