element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Moto Mods
  • Products
  • Manufacturers
  • Moto Mods
  • More
  • Cancel
Moto Mods
Forum I2C Addresses Doubled
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Moto Mods to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 59 subscribers
  • Views 1527 views
  • Users 0 members are here
  • mod
  • i2c
  • moto mod
Related

I2C Addresses Doubled

rdecarre11
rdecarre11 over 8 years ago

Good Evening!

Using Make Menuconfig I set the I2C Address to my address (0x98) 0d152. On my shiny new logic analyzer, I see that the address was 0x30, followed by a NAK.

I changed the address to 0x9A, 0d154, and the address is now 0x34 followed by a NAK.

 

Printing the address on the lldbg seems to agree with the defconfig setting, so that is not the issue.

 

Some maths tells me that this means the Address that the MDK is attempting to use is double that of the one I enter... Strange indeed.

0x98 * 2 = 0x130, since the address is a uint_8t that gets trimmed off at 0x30

0x9A * 2 = 0x134, same, trimmed at 0x34.

 

To finish off the test I tried using 0x4C, 0d76, (half of my real address) and on the scope I see Address 0x98 followed by an ACK and data!

 

Success, shrouded in mystery.

 

Furthermore, the data (a register value from my DAC) is sent back twice after calling a single read. Not sure if anybody has ever seen that before but it is a separate issue.

  • Sign in to reply
  • Cancel

Top Replies

  • COMPACT
    COMPACT over 8 years ago in reply to COMPACT +1
    It's already been said - There are two schools of thought for I2C addresses. 1. Treat the 7 bit address field as though it is left padded with a 0 and ignore the R/~W bit. (Range 0x00-0x7F) (As used by…
  • michaelkellett
    michaelkellett over 8 years ago

    I suspect that you are suffering from confusion (not just your own image) about what is the I2C address.

     

    Download the official I2C spec from

     

    https://www.i2c-bus.org/specification/

     

    and on page 13 (amongst others) you'll see that the first byte in a message from the master contains the address in the most significant 7 bits but that the R/W bit is in position zero. (The page 13 diagram helpfully numbers the bits in a weird way.)

     

    The address is in bits 7  down to 1 so an address of 0x10 (b00010000 looks like b0010000x  where x is the R/W bit. If your logic analyser is not I2C aware it won't get this.

     

    The confusion arises because you can either say the address is the code sent in the byte with bit zero masked out or that it is encoded in the 7 most significant bits. I hope this helps but I won't go so far as to hope that it's clear !

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • rdecarre11
    rdecarre11 over 8 years ago in reply to michaelkellett

    Thanks Michael, I double-checked my settings and took another trace this morning.

    image

    Blurry, but this is the `write` to an address set in menuconfig as 0d76 (0x4C).

    SCL is the second trace, counting bits shows address (TX'd MSB-first) 0b1001100 + 0 at the end for a write operation. That is 0x98...

     

    Ramlog Shot - (ignore tfa9890, I am re-writing the previous tfa9890 driver)

    image

    You can see the driver echoing the i2c_addr as 0x4C.

     

    Thanks again.

    Robert

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • motomodsdev
    motomodsdev over 8 years ago in reply to rdecarre11

    What is your exact device, I'd like to see the data sheet for it?

     

    It appears that you added the "Volume set to," is that working properly?

    For the rev check, did you update the source so it's actually trying to read the version of that chip, and update the value it's checking against?

     

    Finally, there are multiple i2c busses, are you sure you attached to and configured the proper one?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • rdecarre11
    rdecarre11 over 8 years ago in reply to motomodsdev

    The device is a PCM5142. Page 56 of this:

    http://www.ti.com/lit/ds/symlink/pcm5142.pdf

     

    The Volume set to... is the lines I have added to just read a register (0x3D/3E). That works fine. The Rev check is beyond what I was editing and again, not applicable because this device has no ID registers. I just left it in the code because right now I don't care what it does.

     

    The I2C bus is right. The traces I took were captured from the  PCM5142's SDA and SCL pins. I can see the STM32 sending the i2c commands and the PCM responding.

     

    This is mostly just trying to figure out why the Address is set in Menuconfig to 0d76 (0x4c), but what is actually sent is a 0x98.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • COMPACT
    COMPACT over 8 years ago

    The PCM5142 is looking for a repeated start condition in the midst of a register access (read) so you'll have to generate one.

    Have a look 8.4.1.1.2.6 Timing Characteristics of the data sheet.

     

    From your pictures you're not generating one.

     

    i.e. a falling edge of SDA followed by a falling edge of SCLK.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • rdecarre11
    rdecarre11 over 8 years ago in reply to COMPACT

    I appreciate the input. The previous screenshot was about the Address, not about the register read. I was trying to keep this one on the topic of the strange Address behavior.

    I double checked the rest of my I2C exchange and I do in fact have the repeated start. See this other forum about why the 5142 is not behaving.

    https://e2e.ti.com/support/data_converters/audio_converters/f/64/t/578178

     

    Just to maintain one problem at a time image :

    I would like to focus on the fact that even when I put 0d76 (0x4c) in the Menuconfig, the stm32 sends a 0x98 as an address. (depicted in the waveform above)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • COMPACT
    COMPACT over 8 years ago in reply to rdecarre11

    What is the behaviour when you use i2c-tools?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • COMPACT
    COMPACT over 8 years ago in reply to COMPACT

    It's already been said - There are two schools of thought for I2C addresses.

     

    1. Treat the 7 bit address field as though it is left padded with a 0 and ignore the R/~W bit. (Range 0x00-0x7F)

    (As used by Linux)

     

    2. Treat the 7 bit address field combined with the R/~W to form an 8 bit address. (The physical byte transmitted).

    (i.e. Range (0x00-0xFF) with even addresses for writes and odd addresses for reads.)

     

    Does this explain your doubling of I2C addresses?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • rdecarre11
    rdecarre11 over 8 years ago in reply to COMPACT

    I understand. Not sure why that took so long for me to grasp. image.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • COMPACT
    COMPACT over 8 years ago in reply to rdecarre11

    I'm glad that it helped.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube