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
Path to Programmable
  • Challenges & Projects
  • Design Challenges
  • Path to Programmable
  • More
  • Cancel
Path to Programmable
Blog Watchout for I2C in Minized to talk to On Board Temperature and Accelerometer
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mu.udhay
  • Date Created: 30 Jan 2019 6:58 AM Date Created
  • Views 1342 views
  • Likes 4 likes
  • Comments 1 comment
  • i2c
  • lis2ds12
  • sensor
  • minized
Related
Recommended

Watchout for I2C in Minized to talk to On Board Temperature and Accelerometer

mu.udhay
mu.udhay
30 Jan 2019

I made this post because i found the example code provided in SDK for I2C is not meant for Minized , if it is not realized then it would be frustrating in figuring it out.

I am not going to show how to modify that given(Buggy) piece of code but i change it to make it work (yeah its Working) , i found different alternatives and  I would like to show the Best one which is Easy to Understand and Implement/Change for our Purpose.

Before Going into It,we need to understand few things such as How I2C works and how to use the lis2ds12  sensor from STM used on Minized Board.

Simply putting on:In I2C the PS which is used as master first Sends the 7 bit address on the I2C bus and then the Sensor with that Address Responds to master depending on Read/Write Request sent as the 8th Bit.

In LIS2DS12LIS2DS12 case, we first find the Address of it as it can be 0x1D or 0x1E  based on the A0 pin voltage on LIS2DS12LIS2DS12 ,  by testing WHO_AM_I reg in LIS2DS12LIS2DS12 .

We Read a Register in LIS2DS12LIS2DS12 as follows:

1.)We send the Address (0x1D by Default for LIS2DS12LIS2DS12) from PS I2C master with Write Command for the Next Cycle

2.)We send the Register Address (for Eg:Who_Am_I = 0x0F ) from PS as the Data for the Write cycle and also tell that we will talk to it in Nex Cycle

3.)We send the Address (0x1D ) from PS I2C master with a Read Command for the Next Cycle

4.)Now the Device will send the Data i.e., the Register Value(in this case Value Present in Who_Am_I register )

We compare the Value read with the Rquired value in Who_Am_I register (Its value is fixed at 43h),If it is not equal then the Address should be(0x1E) using that Address we test the Who_Am_I register for its validity.

 

In this way we can read any register or Access Any Register in LIS2DS12LIS2DS12 sensor.

 

In terms of code,I uploaded the two Implemtations of I2C for LIS2DS12LIS2DS12 in my Github repo:

1.)I2Ctest.c is a single source file which Outputs the Temperature and Accerometer values by Intializing the required Register similarly as stated above

https://github.com/uElectron/minizedSDK/blob/master/using_I2C/I2Ctest.c

2.)I found the Hardware Abstraction Layer (HAL)Drivers from ST Microelectronics ,where we can use the HAL functions provided but it requires to Write the Platform Dependent Code for using these Drivers

https://github.com/uElectron/minizedSDK/tree/master/using_I2C/stm_based_i2c

Note here : lis2ds12_reg.c & .h files are the Driver files and I impemented the Platform related Initializations in main.c file itself

 

I should state that when working with LIS2DS12LIS2DS12 using I2C , i found LIS2DS12LIS2DS12 Datasheet from STM very useful , you can also see all the required references in one place:

https://github.com/uElectron/minizedSDK/tree/master/supportDocuments/sensorsDatasheets

 

or get it from ST micro website:

https://www.st.com/en/mems-and-sensors/lis2ds12.html

 

 

I started working on my Project,I post the Project Details in my Next Blog post

  • Sign in to reply

Top Comments

  • rscasny
    rscasny over 6 years ago +1
    Thanks Udhay. Looking forward to your project. Randall
  • rscasny
    rscasny over 6 years ago

    Thanks Udhay. Looking forward to your project.

     

    Randall

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • 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