I2C devices with identical addresses
I'm doing a project where I have to read 4 pressure sensors with an I2C bus. The sensors all have the same address and they do not have any external address lines so I can't put them all on the same bus. To save some I/O lines I thought about using a common SCL and separate SDA lines to each sensor.
Will this work? Also, as long as I monitor the SCL line (in case one slave is slower and holds the line low) can I read the sensors simultaneously?
Paul
Will this work? Also, as long as I monitor the SCL line (in case one slave is slower and holds the line low) can I read the sensors simultaneously?
Paul
Comments
http://learn.adafruit.com/delorean-time-circuit/circuit-trickery
Tom
Yes.
Again, I think this is a yes. Does your sensor use clock stretching? With all the I2C devices I've used (not a whole lot), only the master controls the clock. I have read about clock stretching, but I don't see why you wouldn't be able to read from all devices at once (each on with their own SDA lines) with the precautions you mentioned.
It's relatively common on the forum for people to read from multiple SPI devices (each with a separate data line) at once.
I'll go without any extra IC's as I can then easily modifiy an existing pcb design.
sm
Depends on what you want the wiring to look like.
If you can tolerate running a cable to each sensor, and have the pins, then the split bus you describe would work.
You could use separate SCL lines to make it more fail-safe. OR' ing SCL might save pins, but it loads one pin more, and gives a single point of failure, and is not easy to fault find. "All sensors dead" messages ?
If you want a single cable to do all sensors, then you will need something small at the remote end, with a i2c address,
something like a PCA9542 has 8 ID's itself, so one of those per sensor, would allow a single cable, up to 8 (16?) sensors
sm
-Phil
Do I need to use a LOCK when reading from another cog?
Regards,
sm
I try to explain:
Locks are there to syncronize concurrent access between cogs. They do not really lock anything. They are just 'Flags' so your software can wait for the other cog to finish something. If you need them depends - hm - on your needs ....
Hub-Access is round robin, max one long each cog. So writing a long is 'atomic' and does not get interrupted by some other cog. But when your cog 1 writes 3 longs after each other it will take 3 hub-cycles and the cog 2 might read one of them inbetween.
In case of your compass-example this will not matter at all - so you do NOT need locks.
If you - lets say - have some serial driver writing bytes into hub-ram (taking one hub-cycle per byte) and you are transferring 4 bytes representing a long - then you may get in trouble when the second cog reads that long while it is getting changed by the first cog, writing one byte after the other.
Then you need a lock so the second cog waits until all 4 bytes are written, to make sure you are not reading a 'incorrect' long, half the new value and half the old one or something like that.
Locks are very useful to mark resources as 'temporary blocked' but in fakt you will use them very rarely.
hope this helps
Enjoy!
Mike
Many thanks,
sm