Shop OBEX P1 Docs P2 Docs Learn Events
I2C mm problem — Parallax Forums

I2C mm problem

jgjonolajgjonola Posts: 27
edited 2005-09-02 08:00 in General Discussion
Hey guys,

I am using the multi master plus dual uart virtual perf. and changing it to suit my needs.· I have run into a problem.· It gets stuck while checking weather it has lost arbitration.· If i comment out the arbitration lines the program works fine (I have only one master right now, plan to add another).· Also, i have found that while it is stuck, if i take the pull up resistor off and then put it back on, it starts working.· (im guessing that is making the data line go low and then high again.)· Any suggestions?

Thanks,
John Gjonola

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-25 06:00
    According to sxlist.com a multimaster version does exist but may be incorrect.

    Please post your multimaster program so we can check.

    regards peter
  • jgjonolajgjonola Posts: 27
    edited 2005-08-25 18:45
    Ok attached is is the code...· I have commented some parts to show where i was thinking the problem might sit.· I have modified the program to write characters to a display, and the I2C memory, then read them back and display them.· That's all it does right now anyways.

    Thank you,
    John Gjonola·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-30 09:10
    change updating I2C port (line 336)

    ··bank·I2CM···;1 ; Select Master I2C bank
    ··mov·w,I2CM_port_buf··;1
    ··and·w,#%00000011··;1·;keep current SDA and SCL direction
    ··or·w,#%00000100··;1·;pin2 is input
    ··mov·!i2c_port,w··;1 ; Update the I2C port with the buffered port data

    regards peter
    ·
  • jgjonolajgjonola Posts: 27
    edited 2005-08-31 02:16
    Thanks Peter,
    I will try that out later tonight!

    Your the best!

    John Gjonola
  • jgjonolajgjonola Posts: 27
    edited 2005-09-01 17:36
    Peter,

    I made the change that you suggested, but it still has the same problem. If i take out the arbitration code, then it works, if not, it just hangs until you disconnect the data line and then reconnect it.

    Thanks,
    John
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-02 06:47
    Change RA_init to
    RA_init··equ·%11110100 ··;SX18/20/28/48/52 port A latch init·;could the problem be here?????????????????
    The latch bits 0 and 1 must be 0, so when direction bits 0 and 1 are 0, output is low,
    and when direction bits 0 and 1 are 1, output is pulled high by the external 4.7k ohm
    pullup resistors. lines SDA and SCL must have 4.7k pullups)

    All the changes are done in the attached code.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-02 07:06
    in do_I2C_W: you have

    ··sb·I2CM_lost_arb···; if arbitration was lost then wait a while and try again
    ··jmp·@:Ive_lost_arb···;IF I COMMENT OUT THIS LINE AND THE LINE BEFORE IT (IN THE READ AND WRITE PARTS OF THE
    ·······;PROGRAM, IT READS AND WRITES JUST FINE, IF NOT, I MUST PHYSICALLY DISCONNECT THE
    ·······;PULL UP RESISTOR ON THE SDA LINE AND RECONNECT IT FOR THE PROGRAM TO WORK.

    Arbitration is lost if I2CM_lost_arb is set,
    so it should be:

    ··snb·I2CM_lost_arb···; if arbitration was lost then wait a while and try again
    ··jmp·@:Ive_lost_arb···;(jump if I2CM_arb_lost set) IF I COMMENT OUT THIS LINE AND THE LINE BEFORE IT (IN THE READ AND WRITE PARTS OF THE
    ·······;PROGRAM, IT READS AND WRITES JUST FINE, IF NOT, I MUST PHYSICALLY DISCONNECT THE
    ·······;PULL UP RESISTOR ON THE SDA LINE AND RECONNECT IT FOR THE PROGRAM TO WORK.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-02 07:31
    I corrected the arbitration tests also in Read:

    Another dangerous construction is

    ··snb·I2CM_NACK···; Check for no acknowledge
    ··jmp·@do_I2C_W···; try again

    (similar constructions also in Read[noparse]:)[/noparse]

    If for some reason an I2C slave does not acknowledge, your program enters

    an infinite loop. You should really have a timeout on this. When you timeout,

    and not lost arbitration, issue STOP sequence on I2C bus.

    regards peter
  • jgjonolajgjonola Posts: 27
    edited 2005-09-02 07:45
    thanks again Peter... just a question, I looked at the original code (before i made my changes) that i downloaded from the downloads section of the parallax website, and I hadnt changed anything pertaining to this.· So the code posted on parallax's website is wrong?· Should i notify someone?· I found another one with an error to, although a minor one, in the code for the uart vp, the ascii typed schematic that is in the code, does not match the pins in the program.· This caused me about an hour of troubleshooting my wiring, since i had not modified the code downloaded, just programed it into the chip and ran it.· (Not that im upset really, as it really got me to learn the ins and outs of that vp!)

    Thanks again,
    John Gjonola
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-02 08:00
    Any code downloaded from anywhere, may contain errors, or does not work (immediate)
    with your pin assignments. Its always good to check and understand the code
    you use (if you didn't write it, it may take some time to understand, but it will pay off)

    Test the code with your pin assignments and if it then works
    you could notify sxlist.com (you should test with at least 2 masters accessing
    the same eeprom but different areas on that eeprom)

    regards peter
    ·
Sign In or Register to comment.