Shop OBEX P1 Docs P2 Docs Learn Events
Need some help figuring out what is happening here — Parallax Forums

Need some help figuring out what is happening here

DDSDDS Posts: 16
edited 2010-06-24 00:45 in Propeller 1
I have a program that reads some I2C data from a couple of devices. The program (attached) works as follows:

(All this is done in cog 0)
I initialize the I2C chips and get the other objects running.
I call the I2C sampling code and display the data on the serial port (see the top two lines below for what it is supposed to look like).
I then start a new cog with the same sampling routine but it reads bad data IF the "repeat" on line "999" is present but works fine if the "repeat" on line "999" is removed.

My question is: what is happening to all the code in cog 0 (serial driver, I2C driver, etc.) when I include the repeat that makes it work ok when the repeat is missing and it runs out of code to execute?
I realize that the cogs are running the SPIN interpreter and the program is being pulled from the common ram.


Screen dump: Top two lines are correct, lower 3 lines are bad data generated from the same routine but when running in a separate cog.

lChannel= 1 lHex= 0 IMuxC= 00001 EMuxA= 00000 EMuxC= 00001 Addr= 73 Type= 0 Value= 0000FBFC
lChannel= 2 lHex= 0 IMuxC= 00002 EMuxA= 00000 EMuxC= 00001 Addr= 79 Type= 2 Value= 00001840
lChannel= 1 lHex= 0 IMuxC= 00001 EMuxA= 00000 EMuxC= 00001 Addr= 73 Type= 0 Value= 0000FFFF
lChannel= 2 lHex= 0 IMuxC= 00002 EMuxA= 00000 EMuxC= 00001 Addr= 79 Type= 2 Value= 0000FFFF
lChannel= 1 lHex= 0 IMuxC= 00001 EMuxA= 00000 EMuxC= 00001 Addr= 73 Type= 0 Value= 0000FFFF

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2010-06-22 03:07
    You should post the i2dsample file as well. I suspect the probelm is i2csample.init is setting pin to output in cog 0 and you are accessing the i2c in another cog but without the rest of your code I can't check.
  • DDSDDS Posts: 16
    edited 2010-06-22 11:14
    Here is the I2C Driver.
    It is the stock driver from the obex with some minor changes (I don't know what all I changed at this point in time).

    Thanks for the help,

    Don
  • Mike GMike G Posts: 2,702
    edited 2010-06-22 13:23
    I2C allows only one master on the bus at a time. You have two I2C masters? I don't see any bus arbitration. That's a problem with an open collector type bus.
  • DDSDDS Posts: 16
    edited 2010-06-23 14:24
    Single master bus here. My circuitry involves a TI I2C Bus Multiplexer on a single I2C bus.

    The weird thing is that this (stripped down) program works fine if I remove the last "REPEAT" command and let the spin interpreter run out of code but if I include the REPEAT, it fails to talk to the I2C chips.

    I stripped out the clock/calender driver but it did the same thing.

    Exactly what happens to all the program when it runs out?
    Who handles the serial driver, etc. Does it in fact shut the cog down when it runs out of code.
    I can see no conflict when the program is started in a second cog as I effectively terminate the first cog with either no code or a infinite repeat

    Any ideas?
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-06-23 18:58
    I think it's a bad idea to initialize the I2C object in one COG and then using it in another COG. It's cool* that it works in case you keep COG0 running, but when you let COG0 die - which is what you do when removing the repeat - the output will no longer be the same, because dira settings are no longer valid.



    PS : * or better : it makes me wonder ;o)

    Post Edited (MagIO2) : 6/23/2010 7:03:05 PM GMT
  • Mike GMike G Posts: 2,702
    edited 2010-06-24 00:45
    I was wondering about that whole initialize in the current COG then start a new COG thing. I thought the idea was to have two masters.

    I use the Mike Green's basic I2C, works like a charm. Johnny Mac's I2C code works great too.
Sign In or Register to comment.