element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Achievement Levels
    • Benefits of Membership
    • Feedback and Support
    • Members Area
    • Personal Blogs
    • What's New on element14
  • Learn
    Learn
    • eBooks
    • Learning Center
    • Learning Groups
    • STEM Academy
    • Webinars, Training and Events
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Arduino Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Project Groups
    • Raspberry Pi Projects
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Or 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
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Forum Azure Sphere - How to read and write 16-bit register using I2C
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Azure Sphere Starter Kit requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 42 subscribers
  • Views 581 views
  • Users 0 members are here
  • i2c
  • azure sphere
  • mt3620
Related

Azure Sphere - How to read and write 16-bit register using I2C

FrankSteven8877
FrankSteven8877 9 months ago

I am new to this field. I saw an example of read and write 8-bit register using I2C. How to read and write a 16-bit address register? 

Example: the register address is 0x0158, how to use I2CMaster_Read to read the value

Example: the register address is 0x0158, and I want to write 0x01 to this register. How to use I2CMaster_Write to change the value.

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz 9 months ago +1
    Hi, I2C low-level protocol doesn't have a concept of 16-bit registers. If you're new to the field, you really do need to read the I2C specification, it is not very long, or at least the I2C Wikipedia…
  • bwilless
    bwilless 9 months ago +1
    shabaz is correct, you need to look at the device datasheet to understand what to send to your device. What device are you using? Have you looked at any of the i2c examples that are available? Once you…
  • shabaz
    shabaz 9 months ago

    Hi,

    I2C low-level protocol doesn't have a concept of 16-bit registers. If you're new to the field, you really do need to read the I2C specification, it is not very long, or at least the I2C Wikipedia page. That's a good start, because it would have shown you that there are no 16-bit register procedures in the I2C spec itself.

    You need to check the datasheet of the device you're trying to communicate to, in order to see what data bytes (yes, 8-bit data bytes) you can send to the device in order for the device to interpret it as a 16-bit register address, if that is what the device needs. 

    Then, you need to look at the Azure Sphere API and select the best API call to achieve that. Bear in mind, that you don't have 100% flexibility, and not all I2C devices are supported by the API (or at least, that was the case in the past). The API works with many devices, but some devices require certain I2C sequences, that the API might not support. You can check the documentation to pick the appropriate API call after you've determined your requirement (from the device datasheet as mentioned).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • bwilless
    bwilless 9 months ago

    shabaz is correct, you need to look at the device datasheet to understand what to send to your device.  What device are you using?  Have you looked at any of the i2c examples that are available?  Once you understand what the device requires, you create the message in your code and send it to the device.

    Simple example by MSFT:  azure-sphere-samples/Samples/I2C at main · Azure/azure-sphere-samples (github.com). 

    Look at the ResetAndSetSampleRange() function in main.c line 251 for a working example.  Note that a i2c command gets created in a uint8_t array, and the command gets sent to the device.

    • Cancel
    • Vote Up +1 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 © 2023 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