1
\$\begingroup\$

I am having problems to find out exactly how to connect sensors to make a project.

The main issue is that I cannot find a device that can drive enough analog sensor, so I need to use either SPI or I2C.

Now, I have noticed that some sensor basically has the limitation about how many of them you can connect on the same protocol, since they use a fixed address (forgive me if this is incorrect as explanation, but that's what I grasped, looking at the sparse documentation online).

Now, is there an easy way to know which sensor are able to "change" this memory address, so you can use many of them via SPI or I2C? Thanks

EDIT: As sensor I am considering these; for the sampling rate I am not sure how to calculate it; I am a SW engineer, not a hardware engineer. The application is real time collection of data related to position and rotation of an object with the equipment on. The speed of the object measured is not faster than any movement that a human can generate.

ADXL335 and 345 (the latter has SPI and I2C, the former only analog) http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf http://www.analog.com/static/imported-files/data_sheets/ADXL335.pdf

PArallax MMA7455 Accelerometer http://www.parallax.com/sites/default/files/downloads/28526-MMA7455-3-Axis-Accelerometer-Documentation-v1.1.pdf

Bosch BMA180 Accelerometer http://zh.bosch-sensortec.com/content/language4/downloads/BST-BMA180-FL000-03.pdf

L3G4200D Gyroscope http://www.pololu.com/file/0J491/L3G4200D.pdf

Invesense MPU6050 Gyroscope http://invensense.com/mems/gyro/documents/PS-MPU-6000A-00v3.4.pdf

\$\endgroup\$
4
  • \$\begingroup\$ What are you trying to sense? How many of them? There may be other ways than a bunch of devices on a IIC or SPI bus. \$\endgroup\$ Feb 13, 2014 at 23:00
  • \$\begingroup\$ At the moment I need 6 accelerometer and a gyroscope; but I am planning to add also a temperature sensor and magnetometer. I realized that the MC that I was using do not have enough analog input, so I had to steer from that. The other 2 options are I2C or SPI, but I need different brand sensors, since 2 is the max that can go on each line (AFAICT) \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 3:32
  • 1
    \$\begingroup\$ You do realize there are issues with extremely long wires in a I2C bus (and to some extent SPI as well), right? \$\endgroup\$ Feb 14, 2014 at 8:43
  • \$\begingroup\$ I surely do; the farthest that the sensor will be from the computer or controller, is approx .5-3 feet. I was told that the shortest length I have, the better the transmission is (Even using extra durable and shielded cables) \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 21:53

4 Answers 4

6
\$\begingroup\$

I2C will allow you to add as many as there are unique addresses available for the device dependent on line conditions. If you need more addresses than available then you will need to use a I2C hub or multiple I2C buses.

SPI allows as many devices as you can provide nSS lines for, again based on line conditions. A multiplexer such as the '138 can help here.

Regardless of which you pick, the more devices you have the slower you may have to run the clock in order to allow enough slew on the clock and data lines.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks; so to go back to my main question: how do I know how many can I put on a I2C line? SPI instead do not have limitations, other than the slow down due to the number of sensors, from what I can understand \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 3:34
  • 1
    \$\begingroup\$ @newbiez: You can have 1 I2C device with each address on a bus, and I believe there's a maximum capacitive load of 400pF total per bus. See UM10204 for the exact details. \$\endgroup\$ Feb 14, 2014 at 3:56
2
\$\begingroup\$

What you say is true of IIC, but not SPI. SPI devices don't have addresses. They each have their own slave select line instead. Power, ground, clock, data in, and data out are common to all SPI devices, but each needs a separate slave select line.

As for IIC, some devices have a pin or two to allow you to switch them to one of a set of alternate addresses. However, even with two address select pins, you can still only put 4 of the same devices on the IIC bus without doing some other enable/disable yourself.

\$\endgroup\$
5
  • \$\begingroup\$ Some I2C devices have multiple address pins, and those pins have multiple possible states, allowing 8 or 16 or 32 (etc) on a single bus. Add in multiplexers or addressable bus switches and that goes up as well. Then you have parts that come in multiple versions with different address ranges. \$\endgroup\$
    – Passerby
    Feb 14, 2014 at 0:00
  • \$\begingroup\$ Much appreciated; so SPI has less limitations than I2C; I thought that the register could be written so I can decide arbitrarily which register to use for the data :( The MC that I have has 3 I2C channels (don't know who it drive SPI thou). so I could potentially put 4x3=12 sensor on it, without having to switch manually. But how can I tell if I can switch to an alternate address? Is it a parameter given from the manufacturer of the sensor? \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 3:37
  • 1
    \$\begingroup\$ @newbiez: It'll be in the datasheet, usually as Ax pins on the package. \$\endgroup\$ Feb 14, 2014 at 3:58
  • \$\begingroup\$ Thanks! IS this a standard parameter on any data sheet? I am looking at various sensor now, to see which one has this info (checking on Adafruit) \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 4:07
  • \$\begingroup\$ @newbiez alternative address ranges for a i2c part is typically a 2nd part with identical features but a second part number. \$\endgroup\$
    – Passerby
    Feb 14, 2014 at 4:18
2
\$\begingroup\$

I get the feeling you are trying to read several (or many) analogue signals (from sensors), possibly with ADCs. If I'm mistaken, sorry.

Anyway, there are plenty of ADCs on the market that are SPI compatible AND can have their outputs "chained" so that: -

  • One common start conversion triggers all to begin simultaneous conversion
  • One common clock to them all for clocking out data and
  • One SPI line into your MCU (form the last in the chain of ADCs

In effect you initiate conversion to them all simultaneously, wait the appropriate time (busy period while the ADCs are performing the conversion), then clock them all together - the first 12 bits (if it's a 12 bit converter) are from the last in the chain, the next 12 bits are from the 2nd last AND you keep clocking unitl all the "sensor" data is retrieved.

Each ADC has an SDI pin that connects to the SDO of the device earlier in the chain. This way, you only need to provide a "strong" clock suitable for all devices (or split the clock onto mulitple pins).

LTC2370- 16 is a good example: -

enter image description here

Addressing becomes a thing of the past!!!

\$\endgroup\$
4
  • \$\begingroup\$ Thanks Andy; BTW I assume that ADC means analog to digital? I have an Arduino and a Beaglebone as controllers; and I am trying to find out the best way to hook up 6 accelerometers, 1 gyro and eventually, a magnetometer and a temperature sensor on it. Can't use analog, since just the accelerometers would take 18 connections, and neither the Arduino nor the BB can handle so many (BB has 9 if I recall correctly, while the biggest Arduino has 16?). Tried I2C but the sensors that I purchased were conflicting, so I was looking for a way to change registers, or use something like SPI \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 3:42
  • \$\begingroup\$ So your solution would be a hybrid with a ADC that goes on SPI, in conjunction with other SPI sensors? Sorry if I misunderstood, I am still a beginners and I am trying to learn \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 3:43
  • \$\begingroup\$ I would probably choose a much cheaper adc with chain capabilities, possibly 12 bit or maybe 14 bit but yes, that's essentially what I'd do. \$\endgroup\$
    – Andy aka
    Feb 14, 2014 at 8:30
  • \$\begingroup\$ You can always choose an spi adc with analogue multiplexer but throughput of successive conversions for the same analogue input would be slower. Much cheaper and simpler though. \$\endgroup\$
    – Andy aka
    Feb 14, 2014 at 8:32
1
\$\begingroup\$

[This started as a comment, but I've run out of room.]

Many I2C slave devices have partially fixed addresses (as opposed to purely fixed). Upper bits of the 7-bit address are set inside the IC, lower bits of the address are connected to the pins. You can assign different addresses, depending on how you connect these address pins. This is done to allow individual addressing of multiple devices of the same type on one and the same bus.

For an example turn to LM75 (it's a temperature sensor).

block diagram of LM75

Its pins A0, A1, A2 set the lower 3 bits of the I2C address. So, there can be up to 8x LM75 on one I2C bus.

The number of address bits connected to pins varies from one I2C slave device to another.
(I haven't seen devices with more than 4 pins used for addressing.)

Some general* comments about I2C and SPI

* There are exceptions to each of the points below. Neither this list is exhaustive.

I2C is better suited for

  • Larger number of slower signals. (E.g.: temperatures, battery voltages.)
  • Communication when time is not critical. (Leisurely reading an external EEPROM on power-up.)
  • environments with little EMI

SPI is better suited for

  • smaller number of fast signals (audio A/D and D/A, radio comms)
  • environments with moderate EMI (more industrial)

P.S.

That said, it's a bit difficult to give our O.P. a solid advice without knowing more about the O.P.'s signals and sensors.

\$\endgroup\$
3
  • \$\begingroup\$ Very informative! So a sensor may carry different pins, that you need to short? So it knows that you are accessing a specific address for the register? I am in need to gather data in realtime from the sensors (6 accelerometers and one gyro), while the temperature and the magnetometer can give delayed data, since it is not essential. From your explanation, it seems that I2C is not really a good choice, since it would be more fitting for the other sensors and not for the Accelerometers and the gyro. \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 4:06
  • \$\begingroup\$ @newbiez Those points about I2C and SPI are just guidelines. To get the answer to your question "what could work for what I'm trying to do?", you need to start processing hard matter such as datasheets for the sensors and the I2C specification. At the moment, the question written in a hand-wavy form: (1) sampling rates are not posted, (2) sensor models are not posted. \$\endgroup\$ Feb 14, 2014 at 4:35
  • \$\begingroup\$ Thanks Nick; updated the question with the candidate that I am planning to use; for the sampling rate I am not sure how to calculate it \$\endgroup\$
    – rataplan
    Feb 14, 2014 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.