SPI Problem?


Closed Thread
Results 1 to 5 of 5

Thread: SPI Problem?

Hybrid View

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

    Default SPI Problem?

    Hi everyone.I have some problem with SPI which i wanna send data from Master PIC (16F877) with no SS to Slave PIC.I tried transfering data from slave pic to master pic and it worked but when i try to send data from master pic to slave + when i try to read SSPBUF,it shows only "0" or "63" which the symbol "!".How to do that?

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


    Did you find this post helpful? Yes | No

    Unhappy That's cold..

    Nobody answer?.

    Actually, i tried and it worked when i use slave to send data to master and i know about the clock's and other setup as well from the datasheet which specific in "registers".But when i try to send data from master pic to slave pic,dang!it won't work?.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Question Native SPI support in PBP ?

    Hi,

    I didn't get your query? Are you doing a Shiftout or directly setting up your hardware peripheral ?
    Regards

    Sougata

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


    Did you find this post helpful? Yes | No

    Red face Yes.Hardware.

    Hi Soug,

    Yes,i use the hardware setting.Shiftin/out ...yeah...it can work and used it before but plan not to do it again because i really love to know and learn the hardware version itself.You tried it before?.

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


    Did you find this post helpful? Yes | No

    Default Ok..the code..

    The MASTER PIC CODE look like this:

    @_config_HS_OSC



    DEFINE OSC 16


    TRISA = %00000000 'Set All Output
    TRISB = %00000000 'Set All Output
    TRISC = %00010000 'Set PORT.C 4 as Input (SDI)
    TRISD = %00000000 'Set All Output
    TRISE = %00000000 'Set All Output


    SSPEN VAR SSPCON.5 'SSP Enable bit
    CKP VAR SSPCON.4 'Clock Polarity Select
    SMP VAR SSPSTAT.7 'Data input sample phase
    CKE VAR SSPSTAT.6 'Clock Edge Select bit
    SSPIF VAR PIR1.3 'SPI interrupt flag


    i VAR BYTE 'loop counter
    j VAR byte[8] 'Another 1 for testing
    a VAR byte[6] ' Holds 6 character [reserved]

    PORTB.7 = 0:PORTB.6 = 0


    j[0] = 1 ' For testing only.Presets.
    j[1] = 2
    j[2] = 3


    ADCON1 = 7 'All PORT Digital.


    SSPEN = 1 'enable SPI pins
    CKP = 0 'clock idle low
    CKE = 0 'transmit on idle to active transition
    SSPIF = 0 'clear buffer full status
    SMP = 0 'sample in middle of data
    loop:


    gosub senddata 'initiate conversion and send data.
    pause 10
    goto loop



    senddata:


    SSPBUF = "?"
    GOSUB letclear
    IF (SSPBUF <> "!") THEN senddata '"?" Received

    For i = 0 to 5 'loop for 6 characters
    SSPBUF = 0 'write to SSPBUF to start clock
    GoSub letclear 'wait for receipt
    SSPBUF = j[i] 'store received character in array

    Next i 'get next character


    return





    letclear:

    IF SSPIF = 0 Then letclear 'wait for SPI interupt flag
    pauseus 25 'wait for settle and fudge factor
    SSPIF = 0 'reset flag


    Return


    The SLAVE PIC CODE look like this:


    @_config_HS_OSC

    define OSC 16

    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00011000 'set PORTC I/O
    TRISD = %00000000
    TRISE = %00000000


    SSPEN VAR SSPCON.5 'SSP Enable bit
    CKP VAR SSPCON.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


    a VAR BYTE[6] 'Holds 6 characters of data.
    i VAR BYTE 'loop counter


    LCD var PORTB.0 'LCD serial output.

    PORTB.7 = 0 'LED 1
    PORTB.6 = 0 'LED 2

    LCd = 0

    ADCON1 = 7 'All PORT Digital.
    SSPCON = %00000101 'configure SPI slave, no SS

    CKP = 0 'clock idle low
    CKE = 0 'transmit on idle to active transition
    SSPIF = 0 'clear SPI interrupt
    SMP = 0 'sample in middle of data






    loop:
    SSPEN = 0 'disable/enable SSP to reset port
    SSPEN = 1


    goSub letclear 'wait for byte received
    IF (SSPBUF <> "?") Then loop 'wait for ? to start conversion
    gosub done
    gosub getdata

    getdata:

    SSPBUF = "!"

    for i = 0 to 5
    gosub letclear
    a[i] = SSPBUF
    gosub display

    next i

    return


    letclear:

    IF SSPIF = 0 Then letclear 'wait for interrupt flag SSPIF = 0 'reset flag

    Return



    Display:

    lcd = 1
    pause 100

    serout2 lcd,396,[12] 'Refresh LCD.
    serout2 lcd,396,[":",dec SSPBUF]
    pause 500

    goto loop



    done:

    PORTB.7 = 1ause 500:PORTB.7 = 0
    PORTB.6 = 0ause 500:PORTB.6 = 1
    pause 200

    goto loop




    SO WHAT WOULD BE THE PROBLEM??...

    WAUWEEE....

Similar Threads

  1. Problem with connection to SPI SRAM 23K256
    By hankshone in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 27th September 2014, 02:58
  2. Using SPI with External Interrupts
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th June 2008, 04:08
  3. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  4. SPI communication problem (newbie)
    By lm555cn in forum Serial
    Replies: 4
    Last Post: - 3rd March 2008, 15:33
  5. USART SPI problem !
    By TripleS in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th October 2007, 22:09

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