Replace Shiftout with spi


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Hi DarreL

    Thanks for Your help
    Here is a short code that work in the shiftout version, can you see why the
    spi variant not work, i never used spi before.

    The pic is 18F452 and the osc is 16Mhz
    The data i sent to a little TFT display and with the Shiftout it works fine but a little slow

    "Are you connected to the SDO/SCK pins of the pic?
    SDO(PIC) to SDI(slave), AND SCK(PIC) to SCK(slave)."

    Yes
    Lcd_port var PORTC 'Using Port C in the program with the command

    Rs var lcd_port.1
    Cs var lcd_port.2

    Sdata var Lcd_port.5 'spi out pin
    Sclk var Lcd_port.3 'spi clk pin

    DEFINE OSC 16
    TRISC = 0
    contrast var byte
    lcd_out var byte
    contrast = 1

    'spi setup
    SSPEN VAR SSPCON1.5 'SSP Enable bit
    CKP VAR SSPCON1.4 'Clock Polarity Select
    SMP VAR SSPSTAT.7 'Data input sample phase
    CKE VAR SSPSTAT.6 'Clock Edge Select bit
    SSPIF VAR PIR1.3 'interrupt flag - last bit set

    CKP = 0 'clock idle low
    CKE = 0 'transmit on idle to active transition
    SSPIF = 0 'clear SPI interrupt
    SMP = 0


    main:
    gosub adj_contrast
    contrast = contrast + 1
    pause 1000
    goto main


    adj_contrast:
    Command = 0 'command
    Lcd_out = $25 'comand contrast setting
    Gosub Lcd_sendbyte
    Command = 1 'Parameter
    Lcd_out = contrast '..adjust contrast from 0...127
    Gosub Lcd_sendbyte
    return

    Lcd_sendbyte:
    SSPEN = 0 'desable SPI pins
    cs = 0 'Cs = 0 to start of sequence
    sclk = 0 'Clock line to 0
    sdata = 1 '1 = parameter
    If Command = 0 Then
    sdata = 0 '0 = cmd
    Endif
    sclk = 1
    '9 bit ' set it manual to indicate if the next byte is command or parameter
    '----------------------------------------------------------------------
    SSPEN = 1 'enable SPI pins
    SSPBUF = lcd_out 'send variable

    ''''' Shiftout sdata , sclk ,MSBFIRST, [Lcd_out]' 'send bit after bit of the
    'value of variable "Output"
    cs = 1 'Cs to 1 at end of sequence
    Return



    Best regards

    Pedro

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here's a possibility...

    When you disable the SSP module, the pin goes to the state that it was last set to, independant of where the SSP left it.

    After sending the ninth bit, it leaves sclk at 1. So the next time you disable the SSP the SCK pin will go back to 1 and clock in a "bad" bit. The rest of the bits will then be offset by one position.

    Make sure to set the pin to the correct state before disabling the SSP.
    DT

  3. #3
    Join Date
    Jun 2005
    Location
    Penang
    Posts
    40


    Did you find this post helpful? Yes | No

    Default About SPI Too..

    Hi.If i wanna send data from Master PIC to Slave PIC through SPI,can i follow the same concept that were provided in MELABS?.I had tried but it's not working.I am bit confused with clearing SSPBUF which i don't know whether i have to clear it in MASTER or in SLAVE?.Or,i am making mistake in timing?...

Similar Threads

  1. 7 Segment Displays and MAX7219
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st October 2010, 18:30
  2. Smart Star (how to use shift registers)
    By mackrackit in forum Code Examples
    Replies: 3
    Last Post: - 30th November 2008, 20:06
  3. Using SPI with External Interrupts
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th June 2008, 04:08
  4. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  5. SPI instead of SHIFTOUT - MAX7219
    By Momboz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 26th April 2008, 22:58

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