Trouble with I2C - Part 1


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2008
    Posts
    22

    Default Trouble with I2C - Part 1

    Hey all,

    I'm interfacing a Max5477 digital pot to a PIC16F627 with PicBasic Pro V2.47. It took me a bit to get it to work and the problem I see is that the I2CWRITE command's subsequent statements (DataPin, ClockPin, Control, Address, Value) don't work in the order that they're published. In order to get it to work I have to enter it like this:

    I2cwrite PortA.6, PortA.2, Control_NVreg, value, Address

    ie. I have to swap the Value and Address statement to get it to work.

    With:
    Control_NVreg = %00100001
    Value = %10000000
    Address = %01010010



    In all the other I2C posts I looked at everyone is using it in the published order.

    Does anyone have a clue why mine is messed up?

    Mark
    Last edited by munromh; - 15th November 2008 at 18:51.

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


    Did you find this post helpful? Yes | No

    Default

    It's mostly a matter of differences in the naming of the paramaters.

    MAX5477
    Address - Command - Data

    I2CWRITE
    Control - Address - Value

    The I2C Control, is what the MAX calls Address.
    The I2C Address, is what the MAX calls Command.
    What you are calling Control_NVreg, is what the MAX expects for the Command.

    Here's what it should look like without changing the variable names.
    Code:
    I2CWRITE PortA.6, PortA.2, Address, Control_NVreg,[Value]
                              %01010010    %00100001   %10000000
    Also, your address indicates that the A0 pin on the MAX is tied HIGH, with A1 and A2 tied LOW.
    DT

  3. #3
    Join Date
    Nov 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Hey Darryle, thanks for the response.

    Well ..... One of two things, I either don't completely understand your answer or I don't think that's what I'm seeing. Let me walk through it.

    >The I2C Control, is what the MAX calls Address

    Looked at that in more detail, Okay, I agree.

    If the I2C Value, is what Max calls Data then I agree by default that:

    >The I2C Address, is what the MAX calls Command

    So according to the PBP statement:

    I2Cwrite DataPin, ClockPin, Control, Address, Value

    The equivalent Max(imized) statement should be:

    I2Cwrite DataPin, ClockPin, Address, Command, Data

    Which is what you entered when you wrote:

    >Here's what it should look like without changing the variable names.

    And when I put it in that way ....... it ... ahhh .... works! ..... jeez.

    Okay, thanks, I had to walk myself through that. Also, it solved another problem I was seeing but won’t get into here.

    If I might add something else I'm seeing. If I write:

    I2cwrite PortA.6, PortA.2, Address, Command_NVreg, Data_M
    pauseus 100
    I2cwrite PortA.6, PortA.2, Address, Command_NVreg, Data_M
    pauseus 100
    I2cwrite PortA.6, PortA.2, Address, Command_NVreg, Data_M

    For simplicity write 80h to NVreg 21h on slave 29h three times.

    What I see is that the first write statement executed fine:


    However the second write was incorrect:


    And the third was correct:


    This continues on and on and on ....

    What apparently is happening is that the master isn't initiating a Stop sequence and the SCL line stays low .... apparently looking for the next Data Byte (?) ........ which it gets at the start of the next write, but we're trying to write the same thing again.

    Anyway, then a proper Stop sequence is initiated and we're back to normal for the next Write.

    Right around 1.2 mS where the Stop sequence should be SCL goes low before SDA goes high to initiate the Stop sequence.

    Best regards,
    Mark
    Last edited by munromh; - 17th November 2008 at 19:13.

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


    Did you find this post helpful? Yes | No

    Default

    You're missing the brackets around the data.

    The I2C command thinks it's still setting up the write, and doesn't send a STOP.
    <br>
    DT

  5. #5
    Join Date
    Nov 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Ahhh, yes, that works. And you would've thought after reading all those posts about not forgetting the brackets..... I did mess with them a bit, however, I think after my nomenclature confusion between PBP and Maxim I'm not seeing the forest through the trees. Time to step back a bit.

    Thanks,
    Mark

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  2. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13:35
  3. 32 bit square root
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 6th May 2009, 03:37
  4. one line led light make image
    By bioul in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 12:19
  5. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 14:23

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