I2C Slave with a PIC


Closed Thread
Results 1 to 40 of 130

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    ralfmayr wrote on 17th Feb. 2009
    Hi Daniel,
    no, i stopped working on it, it is not possible to get it work... :-(

    I solved my problem using serin/serout.
    But it would be great when we exchange our know-how, so we can solve this together!

    -,Ralf
    I quoted your last year post, just to congratulate with you for the remarkable knowledge you have gained in a year. This will teach new comer that persevering on a subject always pay.

    Thank you for those additional I2C remarks that could be useful.

    Al.
    All progress began with an idea

  2. #2
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Yep,
    last year i made my first experiments with i2cslave,
    but had no time to work on it for 8 months now as
    i was very busy with other things.
    Hope it will help others to come faster to their target.
    -,Ralf

  3. #3
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Hello Al,
    another question:
    What are the three definitions:
    1. DEFINE I2C_SLOW 1
    2. DEFINE I2C_HOLD 1
    3. DEFINE I2C_SCLOUT 1
    do?
    1. => Used with LO > 8MHz and 100kHz devices
    2. => Time Delay during acknowledge?
    3. => Open Collector / Bipolar Clock on SCL? Dont Understand this!

    So: I use PCF8575C and MAX3611 (both 400kHz devices) but both only work
    correct when DEFINE I2C_HOLD 1 and DEFINE I2C_SCLOUT 1 is done.

    Can you help?

    Regards,
    Ralf

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ralfmayr View Post
    Hello Al,
    another question:
    What are the three definitions:
    1. DEFINE I2C_SLOW 1
    2. DEFINE I2C_HOLD 1
    3. DEFINE I2C_SCLOUT 1
    do?
    1. => Used with LO > 8MHz and 100kHz devices
    2. => Time Delay during acknowledge?
    3. => Open Collector / Bipolar Clock on SCL? Dont Understand this!

    So: I use PCF8575C and MAX3611 (both 400kHz devices) but both only work
    correct when DEFINE I2C_HOLD 1 and DEFINE I2C_SCLOUT 1 is done.

    Can you help?

    Regards,
    Ralf
    Hi Ralf,
    I can answer part of #3:
    Open collector means the PIC has 2 states LOW where it takes the pin to ground and an open state where the pin is high impedance, so to get a high state it must have a pull up resistor to supply the power. I do not know what bipolar clock means, have not read up on this yet.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    1. => Used with LO > 8MHz and 100kHz devices
    Yes.

    2. => Time Delay during acknowledge?
    Not Exactly, data transfer can be paused by the receiving device by holding the clock line low, so the receiving device can control the data flow. To enable this function you need the DEFINE I2C_HOLD 1 declared.

    3. => Open Collector / Bipolar Clock on SCL? Dont Understand this!
    Joe already answer to this point with a clear explanation. Let me add that bipolar is a device capable to pullup the lines by itself without the need of external pullup resistors

    So: I use PCF8575C and MAX3611 (both 400kHz devices) but both only work
    correct when DEFINE I2C_HOLD 1 and DEFINE I2C_SCLOUT 1 is done.
    It is usefull to use DEFINE I2C_HOLD 1 as default since it will keep synchronized different devices connected on the I2C bus all with different internal clock.

    I don't know much about PCF8575C and MAX3611 but very likely they are bipolar devices.

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Thank you both for the answers.
    Now i understand.
    So it seems always to be best to work with declaration 2 & 3 with
    400 khz devices. This is what i found out yesterday.
    Have nice eastern!
    Regards,
    Ralf

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Hi all. I need to synchronise an array from one PIC to another (one way only), so I have been working to make a simplified version of the code seen in this thread with just the bare essentials to send the array from slave to master.

    It mostly works, but there is one little bug. I am sending the array over and over again - the test array is 6 bytes and I have assigned test values of 1 2 3 4 5 and 6.

    On the 1st i2cread the master receives 123456. On the 2nd i2cread it gets 234561, and the third 345612. It seems that every time I do an i2cread, the following byte goes missing. The first time I get 123456, the next 1 goes into oblivion and therefore the next packet is 234561.

    I know I can get around this by sending a dummy byte after the array, knowing that it will be lost, but I'd like to know why this is happening if anyone has any ideas?

    Master PIC (18F2620, 40Mhz HSPLL):
    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=%00001111
    CMCON=%00000111
    
    scl             VAR PORTC.3
    sda             VAR PORTC.4                    
    
    i2c_address     VAR BYTE
    
    i2c_data        VAR BYTE[6]
    
    i2c_address=$0A
    
    
    main:
    I2CREAD sda,scl,i2c_address,[STR i2c_data\6]
    LCDOUT $FE,$80,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 1000
    GOTO main
    Slave PIC (18F2620, 40Mhz HSPLL):
    Code:
    DEFINE OSC 40
    
    INCLUDE "DT_INTS-18.bas"  
    INCLUDE "ReEnterPBP-18.bas"
    
    ADCON1=%00001111                            
    CMCON=%00000111         		     
    
    i2c_buffer_full     VAR SSPSTAT.0 
    i2c_read            VAR SSPSTAT.2
    i2c_release_scl     VAR SSPCON1.4 
    
    i2c_data            VAR BYTE[6]
    i2c_data_index      VAR BYTE
    
    dummy               VAR BYTE
    
    SSPADD=$0A          ' I2C Address: $0A
    SSPCON1=$36
    SSPCON2.0=1
    
    i2c_data[0]=1
    i2c_data[1]=2
    i2c_data[2]=3
    i2c_data[3]=4
    i2c_data[4]=5
    i2c_data[5]=6
    
    i2c_data_index=0
    
    ASM
    INT_LIST  macro  
            INT_Handler SSP_INT, _i2c_int_handler, PBP, yes
        endm
        INT_CREATE          
        INT_ENABLE SSP_INT
    endasm
    
    
    main:
    ' main program goes here
    goto main 
    
    
    i2c_int_handler:
    IF i2c_read then
        dummy=SSPBUF
        IF i2c_buffer_full=0 THEN
            SSPBUF=i2c_data[i2c_data_index]
            i2c_data_index=i2c_data_index+1
            IF i2c_data_index=6 THEN i2c_data_index=0
        ENDIF
    ENDIF
    i2c_release_scl=1 
    @ INT_RETURN
    Last edited by Kamikaze47; - 15th August 2010 at 23:04. Reason: spelling
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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