Follow MaxBotix:
Ask A Question
|     Written By: Cody Carlson     |     Date Posted: 04-08-2016     |

Key Takeaways

  • Pull-up resistor values for an I2C circuit are bus speed dependent
  • MaxBotix Inc., sensors require clock stretching for bus speeds above 50kHz
  • Sensor addresses must be properly set and polled for proper operation

What is I2C?

Integrating a number of devices together into one circuit and individually commanding each device allows you to greatly simplify complex circuits. The I2C (inter-integrated circuit) protocol is one option that allows you to place multiple devices on one circuit and independently control each device. XL MaxSonar EZ sensor

The primary components of an I2C circuit consist of a lead device, the master device, and multiple peripheral or slave devices. The role of the master device is to set a bus speed on the clock line and command the peripheral devices. At each high pulse of the clock line the status of the data line is read. The data line sends the communication between the master and slave devices. Reading the data line allows you to string out binary messages being sent between the peripheral, slave, devices and your I2C master device.

What Needs to Happen

In order to have successful I2C communication, the following requirements need to be met. The wiring must be done correctly. The bus speed must be set to a usable speed. The sensor datasheets list the supported clock speeds. The proper pull-up resistors must be present. (This is system and device dependent.) The master device must send the proper commands to the sensor. When all of this happens, the slave device must respond with an acknowledge bit. At this point, successful I2C communication can happen. Verifying that each requirement from this list is being met is an excellent method for I2C troubleshooting.

Addresses

Addresses are key to the success of an I2C circuit. Each slave device on a circuit should have a unique address. To communicate with a specific slave device, the master device announces the unique address of that device. Each slave device should be given an individual address to prevent conflicts between multiple slave devices.

Setting the I2C address requires that you initiate a write at the sensor’s current address. The default sensor address will be listed in the datasheet. Next, you will write three bytes to the sensor starting with the addr_unlock_1 command as the first byte. Write the addr_unlock_2 command as the second byte. Then write the new sensor address as the third byte. We strongly recommend that a separate circuit is used to give each sensor its own address one at a time before placing the sensors in any larger circuits with multiple devices.

If you forget the address of a sensor, you can reset it to its default address. Pin 1 is internally pulled high in the sensor. On power up, the state of this pin is checked; if left high or disconnected, the sensor will use the address stored in memory for I2C communications. If pulled low, the sensor will use its default address for the current power cycle.

While our sensors do not accept 14 bit addressing they can work in a circuit with 14 bit addresses. Whenever a 14 bit address is sent our sensors will not respond. Our sensors will only respond to their 7(8 bit when counting the read write bit) address while ignoring any and all 14 bit addresses.

Troubleshooting

Gaining a better understanding of the I2C interface is one of the best places to start troubleshooting. The I2C interface can prove troublesome at moments. If you find yourself unable to get your circuit working, the I2C forum community is an excellent place to ask questions and familiarize yourself with the finer points of the I2C interface. Raspberry Pi, Texas Instruments, and Arduino, as well as numerous other companies host active I2C forums.

Once you are comfortable, and while you are still researching, you may wish to check the following common I2C missteps.

Pull-up Resistor Value: Among the most common missteps is the use of improper pull-up values. The strength of the pull-up resistors will depend on the clock speed being used as well as the size of the circuit. The I2C specification recommends a resistance value of 4.7 kΩ for 20-100kHz interfaces with good low inductance routing. However, these specifications are for communication between chips on a single PCB. If you have longer cable lengths, it is best to use lower value resistor, such as 1kΩ, and also to use properly shielded cables.

I2C Bus Speed: The bus speed itself can be an issue. Our sensors support I2C clock frequencies up to 400kHz provided clock stretching is supported by the master device. Without clock stretching the sensors can run at speeds up to 50kHz. If you are using a bus speed above 50kHz, you need to verify that your master device supports clock stretching.

Sensor Address: The addressing of the sensor bears repeating. If you are trying to communicate with the sensor, but you are not polling the right address, the sensor will not respond. Errors in setting and polling the sensor address prevent proper communication. We always recommend that you get one sensor working followed by sequentially adding more sensors.

Check the Lines: If available, you may want to view the clock and data lines with an oscilloscope. The following image displays what the “Take a range reading” command looks like on the clock and data lines. There is an issue with your I2C setup if your oscilloscope does not report a similar output. You may wish to verify all of your wiring and coding if your oscilloscope readings do not match. The oscilloscope readout of your clock and data lines are one of the most useful troubleshooting tools for I2C sensors.
oscilloscope readout for the I2C

Some Helpful Tools: There are alternatives to using an oscilloscope to process the the I2C communications. Tools such as an Aardvark I2C/SPI Host Adapter and a Beagle I2C/SPI Protocol Analyzer also work. If the sensor works with these devices and does not work in your system, try looking at the pull-up resistor values for the system as described earlier in the article.

Contact our technical support team if you are have any additional questions or you need help with your I2C setup. We are here to help you succeed.



 
Author: Kathy Kostal  Date: 08-31-2016
Inc 5000 Maxbotix Logo Inc. Magazine Unveils 35th Annual List of America's Fastest Growing Private Companies–the Inc. 5000. MaxBotix Inc., Ranks No. 1752 on the 2016 Inc. 5000 with Three–Year Sales Growth of 213%.
Click here for full article.
Author: Cody Carlson  Date: 08-02-2016
Raspberry Pi 2 board MaxSonar sensors offer a variety of outputs including TTL serial data. This tutorial guides you through the process of setting up your Raspberry Pi 3 with a MaxBotix sensor. Click here for full article.
Author: Scott Wielenberg  Date: 07-26-2016
Full Horn Housing MaxBotix offers an expanded range of packaging options for many of our sensors. Each option provides unique benefits to certain mounting integrations. This article provides a brief overview of each option.
Click here for full article.
Author: Scott Wielenberg  Date: 07-18-2016
Sensor is Tested When providing support, our technical support team may determine that further testing at our facility is the best way to help resolve the issue that you are facing. At this point, they will start the Return Merchandise Authorization (RMA) process. This article will explain what you can expect as your ultrasonic sensor travels through our RMA process.
Click here for full article.
Author: Scott Wielenberg  Date: 07-11-2016
Typical Wall Pipe Many customers have requested the option to mount an ultrasonic sensor in a pipe. During the testing and development cycle, we discovered a number of considerations and requirements that must be met for the application to be successful. When all of these are met, a user may be able to achieve the desired level of success for measuring the liquid level inside of a pipe.
Click here for full article.
Author: Jenney Grover  Date: 06-28-2016
one of the options for outputs On April 19th, we welcomed our supporters to join us for the Grand Opening of the Build Out. Bob and Nita Gross gave a tour of the build out and their vision for the space. We continue to be in awe of the support from our community, our employees, our distributors, and our customers. Thank you for the many years of support, and we look forward to serving you in the years to come.
Click here for full article.
 
 
 
 
 
Signup for notification of our exciting new products and periodic new letters. We are excited to provide the latest information from MaxBotix Inc.