{"id":2931,"date":"2024-10-26T13:48:34","date_gmt":"2024-10-26T13:48:34","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2931"},"modified":"2024-10-26T13:48:36","modified_gmt":"2024-10-26T13:48:36","slug":"how-to-create-a-library-for-sensors-part-1-getting-the-required-information","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2931","title":{"rendered":"How to Create a Library for sensors Part 1: Getting the Required information"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST.webp\" alt=\"\" class=\"wp-image-2932\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST-300x300.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST-150x150.webp 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST-768x768.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST-750x750.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST-400x400.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-26-15.42.39-A-detailed-and-educational-illustration-representing-the-development-of-a-library-for-an-ADXL345-accelerometer-sensor-using-I2C-communication-on-an-ST-250x250.webp 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>In this series guide, we\u2019ll explore building a dedicated, lightweight library to interface with the ADXL345 accelerometer sensor using the I2C protocol on the STM32F4 microcontroller. Creating a custom library from scratch not only provides greater control over sensor configuration and data handling but also allows for easy integration across multiple projects and applications. This hands-on approach will equip you with a strong foundation for developing driver libraries for various I2C-based peripherals in the future.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In part 1, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Gathering the required information.<\/li>\n\n\n\n<li>Connection.<\/li>\n\n\n\n<li>STM32CubeIDE Setup.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Gathering the Required Information:<\/h2>\n\n\n\n<p>Since this guide is focused on creating custom library for adxl345, we shall start from the datasheet of the sensor. The datasheet of the sensor can be found <a href=\"https:\/\/www.sparkfun.com\/datasheets\/Sensors\/Accelerometer\/ADXL345.pdf\" data-type=\"link\" data-id=\"https:\/\/www.sparkfun.com\/datasheets\/Sensors\/Accelerometer\/ADXL345.pdf\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>From the datasheet, we can find the following:<\/p>\n\n\n\n<p>From the features section, we can find the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"684\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-1024x684.jpg\" alt=\"\" class=\"wp-image-2933\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-1024x684.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-300x200.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-768x513.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-1536x1025.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-2048x1367.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-1150x768.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-750x501.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-400x267.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-49-06-250x167.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>10-bit resolution with ability to reach 13-bit for higher g.<\/li>\n\n\n\n<li>Works from 2.0 to 3.6V which is the operating voltage of STM32F4 of 3.3V.<\/li>\n\n\n\n<li>Can work with SPI and I2C mode. In this guide, we are focusing on I2C interface.<\/li>\n\n\n\n<li>It has ability to generate interrupt when new data is available.<\/li>\n<\/ul>\n\n\n\n<p>From the I2C section of the ADXL345, we can find the address for read and write and also the operating frequency.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"449\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-1024x449.jpg\" alt=\"\" class=\"wp-image-2935\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-1024x449.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-300x132.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-768x337.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-1536x674.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-2048x899.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-1150x505.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-750x329.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-400x176.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_15-55-06-250x110.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can work with standard speed of 100KHz and fast mode of 400KHz. This guide shall focus on using the fast mode.<\/li>\n\n\n\n<li>Address of 0x53 when the SDO\/ALT to ground.<\/li>\n<\/ul>\n\n\n\n<p>Since the module used in this guide the address is 0x53, the library we shall build will have the ability to accept the other address in case this address will conflict with the other slave device connected to the I2C bus.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>For now, this is the basic information to get the device connected to our STM32F4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Connection:<\/h2>\n\n\n\n<p>Since the board used in this guide is STM32F411RE Nucleo-64.<\/p>\n\n\n\n<p>The board features Arduino Uno pinout, D14 and D15 features I2C pins as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"609\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-1024x609.jpg\" alt=\"\" class=\"wp-image-2936\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-1024x609.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-300x179.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-768x457.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-1536x914.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-2048x1219.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-1150x684.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-750x446.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-400x238.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-18-16-250x149.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>These pins can be found in the pinout in the user manual of STM32 Nucleo-64 boards (MB1136) as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"508\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-1024x508.jpg\" alt=\"\" class=\"wp-image-2937\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-1024x508.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-300x149.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-768x381.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-1536x762.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-2048x1015.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-1150x570.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-750x372.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-400x198.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-17-28-250x124.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PB8(D15) is SCL which is Serial Clock.<\/li>\n\n\n\n<li>PB9(D14) is SDA which is Serial Data.<\/li>\n<\/ul>\n\n\n\n<p>Hence, the connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"666\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-1024x666.jpg\" alt=\"\" class=\"wp-image-2938\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-1024x666.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-300x195.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-768x499.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-1536x999.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-2048x1331.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-1150x748.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-750x488.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-400x260.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-04-13-250x163.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. STM32CubeIDE Setup:<\/h2>\n\n\n\n<p>Open STM32CubeIDE after selecting the workspace and create new project as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"355\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-1024x355.jpg\" alt=\"\" class=\"wp-image-2940\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-1024x355.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-300x104.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-768x266.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-1536x532.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-2048x709.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-1150x398.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-750x260.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-400x139.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-26-00-250x87.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Select the MCU:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"832\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-1024x832.jpg\" alt=\"\" class=\"wp-image-2941\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-1024x832.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-300x244.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-768x624.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-1536x1248.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-2048x1664.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-1150x934.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-750x609.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-400x325.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-14-250x203.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Give the project a name:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"876\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-876x1024.jpg\" alt=\"\" class=\"wp-image-2942\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-876x1024.jpg 876w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-257x300.jpg 257w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-768x898.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-750x877.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-400x467.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53-250x292.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-27-53.jpg 984w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/figure>\n\n\n\n<p>Make sure the Targeted Project Type is STM32Cube, Language is C and binary type is Executable.<\/p>\n\n\n\n<p>After that, set PB8 and PB9 for I2C1 or I2C3, here we shall use I2C1 as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"658\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-1024x658.jpg\" alt=\"\" class=\"wp-image-2943\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-1024x658.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-300x193.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-768x493.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-1536x987.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-2048x1316.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-1150x739.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-750x482.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-400x257.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-39-21-250x161.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Also, set PA2 and PA3 for Serial2 since they are linked with VCP of onboard ST-Link.<\/p>\n\n\n\n<p>Enable UART as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"771\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-771x1024.jpg\" alt=\"\" class=\"wp-image-2944\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-771x1024.jpg 771w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-226x300.jpg 226w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-768x1020.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-1156x1536.jpg 1156w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-1150x1528.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-750x996.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-400x531.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17-250x332.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-41-17.jpg 1504w\" sizes=\"(max-width: 771px) 100vw, 771px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next Enable I2C1 as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"918\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-1024x918.jpg\" alt=\"\" class=\"wp-image-2945\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-1024x918.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-300x269.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-768x688.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-1150x1031.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-750x672.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-400x359.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25-250x224.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-42-25.jpg 1504w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>From parameter Settings of I2C1 enable the fast mode as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"978\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-978x1024.jpg\" alt=\"\" class=\"wp-image-2947\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-978x1024.jpg 978w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-287x300.jpg 287w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-768x804.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-750x785.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-400x419.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07-250x262.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-43-07.jpg 1106w\" sizes=\"(max-width: 978px) 100vw, 978px\" \/><\/figure>\n\n\n\n<p>From Clock Configuration tab, set the frequency to maximum of 100MHz as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"495\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-1024x495.jpg\" alt=\"\" class=\"wp-image-2948\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-1024x495.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-300x145.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-768x371.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-1536x742.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-2048x989.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-1150x555.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-750x362.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-400x193.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-44-17-250x121.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>From Project Manager tab, select Code Generation and enable Generate peripheral initialization as pair of .c\/.h files per peripheral as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"363\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-1024x363.jpg\" alt=\"\" class=\"wp-image-2949\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-1024x363.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-300x106.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-768x273.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-1536x545.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-2048x727.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-1150x408.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-750x266.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-400x142.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/10\/2024-10-26_16-45-24-250x89.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the configuration.<\/p>\n\n\n\n<p>Save the project and this will generate the project.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In part 2, we start developing the library.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this series guide, we\u2019ll explore building a dedicated, lightweight library to interface with the ADXL345 accelerometer sensor using the I2C protocol on the STM32F4 microcontroller. Creating a custom library from scratch not only provides greater control over sensor configuration and data handling but also allows for easy integration across multiple projects and applications. This [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-2931","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2931"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2931"}],"version-history":[{"count":3,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2931\/revisions"}],"predecessor-version":[{"id":2950,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2931\/revisions\/2950"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}