Please help with i2cslave i2c slave


Closed Thread
Results 1 to 3 of 3
  1. #1
    cycle_girl's Avatar
    cycle_girl Guest

    Default Please help with i2cslave i2c slave

    I have searched through posts and read application notes, especially AN734 and
    http://www.melabs.com/resources/samp...p/i2cslave.bas

    However, I am still unable to get my 16F690 to operate in slave mode. In the code below, if SSPIF ever gets set, I'm supposed to get 5 blinks of LED1. I send READ and WRITE commands to i2c address 0, but never get the 5 blinks.

    I'm also monitoring SCL and SDA and the PIC is not generating an ACK (not pulling down SDA after the 8th clock cycle of the control byte). Can anyone help? cycle_girl

    ' Alias pins
    scl VAR PORTB.6 ' I2C clock input
    sda VAR PORTB.4 ' I2C data input

    ' Define used register flags
    SSPIF VAR PIR1.3 ' SSP (I2C) interrupt flag
    BF VAR SSPSTAT.0 ' SSP (I2C) Buffer Full
    R_W VAR SSPSTAT.2 ' SSP (I2C) Read/Write
    D_A VAR SSPSTAT.5 ' SSP (I2C) Data/Address
    CKP VAR SSPCON.4 ' SSP (I2C) SCK Release Control
    SSPEN VAR SSPCON.5 ' SSP (I2C) Enable
    SSPOV VAR SSPCON.6 ' SSP (I2C) Receive Overflow Indicator
    WCOL VAR SSPCON.7 ' SSP (I2C) Write Collision Detect

    ' Define constants
    I2Caddress CON $00

    ' Allocate RAM
    datain VAR BYTE ' Data in
    counter1 VAR BYTE

    ' Initialize I2C slave mode
    TRISC = %00000000 ' set PORTC to output ffor LEDs
    TRISB = %11111111 ' set PORTB to all input for i2c

    SSPADD = I2caddress ' Set our address
    SSPCON = $36 ' 00110110 Set to I2C slave with 7-bit address
    PIE1.3 = 1 ' SSP (I2C) interrupt enable
    INTCON.6 = 1 ' PEIE = Peripheral Interrupt Enable bit
    INTCON.7 = 1 ' GIE enable
    SSPIF = 0
    SSPSTAT = $00

    mainloop:

    PORTC = $0A ' turns on LED1 and LED3 so I can see that it's running

    IF SSPIF THEN
    SSPIF = 0 ' clear the flag
    datain = SSPBUF
    SSPBUF = datain
    CKP = 1
    GOSUB Blink5 ' let me know that i2c interrupt occurred
    ENDIF

    GoTo mainloop ' Do it forever

    Blink5:
    For counter1 = 1 to 5
    PORTC = $02
    PAUSE 100
    PORTC = $00
    PAUSE 100
    NEXT
    RETURN

    end

  2. #2
    cycle_girl's Avatar
    cycle_girl Guest


    Did you find this post helpful? Yes | No

    Default Found the problem

    I found the problem myself...

    ANSELH = $00

    I needed to set my SDA line to digital. Apparently, it defaults to analog.

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


    Did you find this post helpful? Yes | No

    Default Good job!

    <img src=http://www.picbasic.co.uk/forum/attachment.php?attachmentid=639&stc=1&d=1133445289 >
    Attached Images Attached Images  
    Steve

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

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. Another I2C Slave Routine Problem
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 05:50
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  5. I2C slave
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th March 2008, 03:46

Members who have read this thread : 1

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