SPI basics


Results 1 to 22 of 22

Thread: SPI basics

Threaded View

  1. #15
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default first try, first headache....

    Well then,

    Here is my first attempt to write the character "A" on my display via SPI.

    As my code is for sure far too simplistic, it doesn't work ...anyway, it's not a surprise; I'm unfortunately used to this.

    There is that "RS" line I don't really understand how I need to handle it but from the datasheet, I think I can tie it LOW (detail attached).

    Any help or advice to get this "A" shining on my display is welcome

    Code:
    <html><head></head><body><!--StartFragment--><pre><code><font color="#000080"><i>' PIC 16F690 Fuses
    </i></font><font color="#008000">@ DEVICE FCMEN_OFF
    @ DEVICE IESO_OFF
    @ DEVICE BOD_OFF
    @ DEVICE CPD_OFF
    @ DEVICE PROTECT_OFF
    @ DEVICE MCLR_OFF
    @ DEVICE PWRT_OFF
    @ DEVICE WDT_OFF
    @ DEVICE XT_OSC
    
    </font><font color="#000080"><i>' Registers   76543210
    </i></font>OPTION_REG = %10000000 <font color="#000080"><i>'PORT A&amp;B Pull-Ups disabled (look WPUA &amp; WPUB)
    </i></font>ANSEL      = %00000000 <font color="#000080"><i>'Disable analog inputs Channels 0 to 7
    </i></font>ANSELH     = %00000000 <font color="#000080"><i>'Disable analog inputs Channels 8 to 11
    </i></font>ADCON0     = %00000000 <font color="#000080"><i>'A/D Module is OFF
    </i></font>CM1CON0    = %00000000 <font color="#000080"><i>'Comparator1 Module is OFF
    </i></font>CM2CON0    = %00000000 <font color="#000080"><i>'Comparator2 Module is OFF
    </i></font>INTCON     = %00000000 <font color="#000080"><i>'INTerrupts CONtrol
    </i></font>TRISA      = %00000000 <font color="#000080"><i>'Set Input/Output (0 to 5)
    </i></font>PORTA      = %00000000 <font color="#000080"><i>'Ports High/Low (0 to 5)
    </i></font>TRISB      = %01000000 <font color="#000080"><i>'Set Input/Output (4 to 7)
    </i></font>PORTB      = %00000000 <font color="#000080"><i>'Ports High/Low (4 to 7)
    </i></font>TRISC      = %01000000 <font color="#000080"><i>'Set Input/Output (0 to 7)
    </i></font>PORTC      = %01000000 <font color="#000080"><i>'Ports High/Low (0 to 7)
    
    'set up SPI master mode
    </i></font>SSPSTAT = %00000000
    SSPCON  = %00100000
    
    
    <font color="#000080"><i>'-------------------------------------------------------------------------------
    ' EA DOGMxxx-A SPI mode LCD circuitry (see datasheet)
    ' &quot;RS&quot; is pulled LOW = Instruction register (for write)
    
    '-------------------------------------------------------------------------------
    </i></font>INIT:
    SCK     <b>VAR </b>PORTB.6 <font color="#000080"><i>'Clock pin
    </i></font>CSB     <b>VAR </b>PORTC.6 <font color="#000080"><i>'LOW active pin
    </i></font>SDO     <b>VAR </b>PORTB.7 <font color="#000080"><i>'Data Out pin
    
    ' &quot;EA-DOGM162L-A&quot; LCD display Mandatory settings
    '$39 'Function Set: 8 bits bus mode
    '$1C 'Bias set
    '$52 'Power control + Contrast (HiByte)
    '$69 'Follower control
    '$75 'Contrast (LowByte)
    
    </i></font><b>PAUSE </b>1000  <font color="#000080"><i>'Time to settle Vdd (THIS IS VERY IMPORTANT for this display!!!)
    
    </i></font><b>LOW </b>CSB     <font color="#000080"><i>'set LCD active
    </i></font><b>SHIFTOUT </b>SDO,SCK,1,[$39,$1C,$52,$69,$75]  <font color="#000080"><i>'MSBFIRST
    </i></font><b>HIGH </b>CSB    <font color="#000080"><i>'set LCD inactive
    
    '-------------------------------------------------------------------------------
    </i></font>MAIN:
    
    <font color="#000080"><i>' Clear display
    </i></font><b>LOW </b>CSB
    <b>SHIFTOUT </b>SDO,SCK,1,[$1]
    <b>HIGH </b>CSB
    
    <font color="#000080"><i>' Sent character &quot;A&quot; to display
    </i></font><b>LOW </b>CSB
    <b>SHIFTOUT </b>SDO,SCK,1,[$41]
    <b>HIGH </b>CSB
    <b>
    END
    </b></code></pre><!--EndFragment--></body>
    </html>
    NB: thanks Jerson, your explanation made the SPI principle get out my head's myst
    Attached Images Attached Images  
    Last edited by flotulopex; - 25th July 2010 at 18:01.
    Roger

Members who have read this thread : 0

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

Posting Permissions

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