Replace Shiftout with spi


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2006
    Posts
    60

    Default Replace Shiftout with spi

    Hello

    I want to replace this instruction
    Shiftout sdata , sclk ,MSBFIRST, [Lcd_out]
    to the spi comunication
    I have never use spi comunication, can anyone help me, a sample code perhaps

    thanks in advance

    Pedro

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    euh.. SHIFTOUT is already SPI!

    Give us more details!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    euh.. SHIFTOUT is already SPI!

    Give us more details!
    I believe Pedro means hardware SPI. With that assumption, it would be good to know which processor you are working with Pedro. Shiftout/in works very well and it's easy(Thanks Melabs!) buuuuut... It can be slow. How fast do you need to go?

    Ron

  4. #4
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Hi Ron

    Yes, i mean the hardware SPI
    Like You say the Shifout work very good but it is slow, i need to send a byte
    quickly to a lcd and perhaps with the hardware SPI pin can i have more speed
    The controller that i use is PIC 18F452

    Have You a sample code to do that, don't forget it must sent the MSBFIRST

    Thanks

    Regards

    Pedro

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


    Did you find this post helpful? Yes | No

    Default

    Pedro,

    There's a sample SPI program on the meLabs website.

    http://www.melabs.com/resources/samples.htm

    Look for spimast.bas

    HTH,
    DT

  6. #6
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Hi

    Yes i see the sample on melabs site but don't understand how to sent
    with the spi out pin the msbit first, say bit7, bit6, bit5, ... bit0

    Thanks for help
    Pedro

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


    Did you find this post helpful? Yes | No

    Default

    The MSSP always sends data MSB first.
    <br>
    DT

  8. #8
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Hello Darrel

    my board work correct with this instruction
    Shiftout sdata , sclk ,MSBFIRST, [var_out]

    Do You know the correct SPI setup to use the hardware SPI to do that?

    I try with this and have no function
    '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

    TRISC = 0

    CKP = 0 'clock idle low 'have changed to 1 for testing but no ok
    CKE = 0 'transmit on idle to active transition 'have changed to 1 for testing
    'but no ok
    SSPIF = 0 'clear SPI interrupt
    SMP = 0

    main:
    SSPEN = 1 'enable SPI pins
    SSPBUF = var_out 'send array variable
    Return

    Have a idea how to fix that?

    Thank You

    Regards

    Pedro

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


    Did you find this post helpful? Yes | No

    Default

    For MSBFIRST, you have it correct.

    CKP = 0
    CKE = 0

    Which PIC are you using?
    What OSC frequency are you using?
    What is it sending data to?

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

    Also, in this code...
    Code:
    main:
        SSPEN = 1 'enable SPI pins 
        SSPBUF = var_out 'send array variable
    Return
    Since no subroutine was called, the program will reset when it gets to the Return.
    <br>
    DT

  10. #10
    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

  11. #11
    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

  12. #12
    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