I2C Slave with a PIC


Closed Thread
Results 1 to 40 of 130

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    In your previous code with the F88, 3 is not a valid I2C address.
    In the current code, $B is not a valid I2C address.

    They should be a multiple of 2.
    Bit 0 is reserved for the R/W bit.
    DT

  2. #2
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    Quote Originally Posted by Darrel Taylor View Post
    In your previous code with the F88, 3 is not a valid I2C address.
    In the current code, $B is not a valid I2C address.

    They should be a multiple of 2.
    Bit 0 is reserved for the R/W bit.
    Hi Darrel,
    Thanks for replying, I did some testing on 1Master and 1Slave with these address($02,$04,$06,$08,$10,$12,$14) and works fine. But when I trying to add Slave #2 I get "0 0 0 0 0 0". It only reads on the Slave #1 correct (displays "1 2 3 4 5 6").
    This is how I code to read the 2nd Slave.
    Code:
    DEFINE OSC 40
    
    
    DEFINE I2C_HOLD 1
    
    
    DEFINE LCD_DREG         PORTB          
    DEFINE LCD_DBIT         0              
    DEFINE LCD_RSREG        PORTB         
    DEFINE LCD_RSBIT        4             
    DEFINE LCD_EREG         PORTB          
    DEFINE LCD_EBIT         5             
    DEFINE LCD_BITS         4           
    DEFINE LCD_LINES        2              
    DEFINE LCD_COMMANDUS    2000         
    DEFINE LCD_DATAUS       50           
    PAUSE 100
    LCDOUT $FE,1,$FE,2
    
    
    ADCON1=001111
    CMCON=000111
    
    
    scl             VAR PORTC.3
    sda             VAR PORTC.4                    
    
    
    i2c_address     VAR BYTE
    i2c_address2     VAR BYTE
    
    
    i2c_data        VAR BYTE[6]
    i2c_data2       VAR BYTE[6] 
    
    
    
    
    main:
    
    
    i2c_address=$10
    pause 200
    I2CREAD sda,scl,i2c_address,[STR i2c_data\6]
    LCDOUT $FE,$80,"1> ",DEC i2c_data[0]
    LCDOUT " ",    DEC i2c_data[1]
    LCDOUT " ",    DEC i2c_data[2]
    LCDOUT " ",    DEC i2c_data[3]
    LCDOUT " ",    DEC i2c_data[4]
    LCDOUT " ",    DEC i2c_data[5]
    
    
    PAUSE 500
    LCDOUT $FE,1
    '*********************************************
    i2c_address2=$14
    pause 200
    I2CREAD sda,scl,i2c_address2,[STR i2c_data2\6]
    LCDOUT $FE,$80,"2> ",DEC i2c_data2[0]
    LCDOUT " ",    DEC i2c_data2[1]
    LCDOUT " ",    DEC i2c_data2[2]
    LCDOUT " ",    DEC i2c_data2[3]
    LCDOUT " ",    DEC i2c_data2[4]
    LCDOUT " ",    DEC i2c_data2[5]
    
    
    PAUSE 500
    LCDOUT $FE,1  
    GOTO main
    BTW the code for Slave1 and Slave2 are identical (Slave#1 is address $10 and Slave#2 is address $14)
    What I'm doing wrong in the code? I appreciate very much your help.

    Thanks,
    Tacbanon
    Last edited by tacbanon; - 27th April 2012 at 11:53.

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


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    If you comment out the first I2CREAD, is it able to read from the second slave?

    If you change the order so that it reads the second slave first, is it then unable to read the first slave?
    DT

  4. #4
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    If you comment out the first I2CREAD, is it able to read from the second slave?
    Yes it is able to read.
    If you change the order so that it reads the second slave first, is it then unable to read the first slave?
    Nope, displays "0 0 0 0 0 0" for first Slave, 2nd Slave shows "6 5 4 3 2 1"
    Last edited by tacbanon; - 27th April 2012 at 16:57.

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


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    It sounds like a buffer overflow.

    ... bad comment deleted ... duh!!

    If you post or email your .DSN, I'll take a closer look.
    Last edited by Darrel Taylor; - 28th April 2012 at 02:20.
    DT

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    Thanks Darrel, oh sorry to ask this, but how do I send a winrar file?

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


    Did you find this post helpful? Yes | No

    Default Re: Please help me understand how the application works

    Steve

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

Similar Threads

  1. Problem with PICto PIC I2C MASTER-SLAVE
    By juanen19 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th June 2013, 02:58
  2. PIC as I2C Slave
    By Mainul in forum General
    Replies: 4
    Last Post: - 5th January 2013, 13:23
  3. I2C Slave, config Vref - + in pic with ADC
    By sebapostigo in forum PBP Wish List
    Replies: 4
    Last Post: - 5th March 2007, 03:21
  4. Pic as an i2c slave
    By Robert Soubie in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2007, 21:11
  5. Use pic as slave in I2C
    By robert0 in forum General
    Replies: 2
    Last Post: - 3rd February 2006, 19:26

Members who have read this thread : 2

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