SPI basics


Results 1 to 22 of 22

Thread: SPI basics

Threaded View

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


    Did you find this post helpful? Yes | No

    Default unsuccessfull until now

    I've been working on this for hours now, unsuccesfully

    Finally, I reduced my code to a minimum and started some readings on the scope. In fact, the current aim is now to make sure the PIC is working as it should - not matter what data/command is sent. I'm trying to get something like this (from the display's datasheet):



    ..but this is what I see on my scope (where SDO=SI and SCK=SCL):


    At a very first glance, one can see that the SCK (SCL) doesn't "tick" as it should. I even tried another PIC but no change.

    I have checked and re-checked the hardware (connections and wiring) many times and I think I haven't missed something there. I also put 10k pull-down resistors on all four wires but this didn't make any difference.

    Here's my "non-efficient" but as simple and readable as possible code.
    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 INTRC_OSC_NOCLKOUT
    
    </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>OSCCON     = %01100000 <font color="#000080"><i>'Internal RC set to 4Mhz
    </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>WPUB       = %00000000 <font color="#000080"><i>'Disable weak pull-ups
    </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      = %00000000 <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      = %00000000 <font color="#000080"><i>'Set Input/Output (0 to 7)
    </i></font>PORTC      = %00000000 <font color="#000080"><i>'Ports High/Low (0 to 7)
    
    'setup SPI master mode
    </i></font>SSPSTAT.6 = 1 <font color="#000080"><i>'Data transmitted on rising edge of SCK
    </i></font>SSPCON.5  = 1 <font color="#000080"><i>'SSP is enabled
    </i></font>SSPCON.4  = 0 <font color="#000080"><i>'Idle state for clock is a low level
    </i></font>SSPCON.1  = 1 <font color="#000080"><i>'SPI Master mode, clock = FOSC/64
                                    
    '-------------------------------------------------------------------------------
    </i></font>INIT:
    RS      <b>VAR </b>PORTB.5 <font color="#000080"><i>'instruction=0 / data=1
    </i></font>SCK     <b>VAR </b>PORTB.6 <font color="#000080"><i>'Clock pin
    </i></font>CSB     <b>VAR </b>PORTB.7 <font color="#000080"><i>'LOW active pin
    </i></font>SDO     <b>VAR </b>PORTC.7 <font color="#000080"><i>'Data Out pin
    </i></font>Mode    <b>CON </b>1       <font color="#000080"><i>'MSBFIRST - Clock idles low. 
    
    '-------------------------------------------------------------------------------
    </i></font><b>PAUSE </b>1000  <font color="#000080"><i>'Time to settle display's Vdd
    
    </i></font>MAIN:
    
    <b>LOW </b>CSB     <font color="#000080"><i>'set LCD active
    </i></font><b>PAUSE </b>40
    <b>LOW </b>RS      <font color="#000080"><i>'set Register to &quot;instruction&quot;
    </i></font><b>PAUSEUS </b>3
    
    <b>SHIFTOUT </b>SDO,SCK,Mode,[$39]
    <b>PAUSE </b>30
    
    <b>HIGH </b>CSB
    <b>PAUSE </b>30
    
    <b>GOTO </b>MAIN:
    
    <b>END</b></code></pre><!--EndFragment--></body></html>
    It looks like something is missing in the SSP setup; what is it?

    The error must be obvious, but I can't see where the fish is!
    Attached Images Attached Images   
    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