App note: Reading two bytes of data over I2C

in app notes by DP | 6 comments

Some I2C sensors and devices store more then one byte of data that needs to be read by a microcontroller. Many of these devices change the data once a stop bit has been received.

Problems might occur if the data is read by the microcontroller in two consecutive 1byte transactions. If so, the microcontroller will send a stop bit between two data transmissions, thus prompting the device to update it’s data and corrupt the second byte.

Here is a app note from Maxim explaining how to properly read two bytes without any data corruption. Instead of sending a stop bit after the first byte is received, a repeated start should be sent by the master, thus insuring no data corruption will occur.

This entry was posted in app notes and tagged , , .

Comments

  1. Colin says:

    Isn’t this sort of an obvious part of the protocol?

  2. rsdio says:

    It’s not obvious when someone blindly calls an opaque serial API twice to create a 16-bit access from two 8-bit accesses. For firmware developers who code at the lowest level, this sort of thing is easy, but for folks who only write C and don’t read data sheets then it might be an easy mistake.

    • Steve says:

      …and if Maxim went through the trouble of writing the app note, then I would say others (besides hobbyists) are running into the same corruption issue.

    • Colin says:

      Well, if you’re using C functions to interface with an I2C device, you should read the data sheet for the device. Look up the protocol you intend on using… plain and simple. Writing app notes to market towards people who don’t read data sheets seems… stupid.
      What I’m saying is that this information is a 10 second Google search.

      • rsdio says:

        Google search is always fast and easy when you already know the answer. But if you had a 10-bit ADC that was only failing randomly and infrequently, but otherwise working just fine, then I doubt a Google search on the specific problem would reveal the actual solution. Besides, this one App Note is shorter than any of the multiple data sheets that it is relevant to.

        Granted, I have enough experience not to make these kinds of mistakes, so I didn’t learn anything new. Yet this App Note was very popular – more popular than most. So it must appeal to some readers. If you’re not one of them, then fine, go design some awesome hardware and/or firmware!

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.