{"id":3114,"date":"2024-12-29T04:18:18","date_gmt":"2024-12-29T04:18:18","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=3114"},"modified":"2024-12-29T04:18:19","modified_gmt":"2024-12-29T04:18:19","slug":"creating-a-library-for-pcf8591-ad-da-module-part-1-getting-the-required-information","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=3114","title":{"rendered":"Creating a Library for PCF8591 AD\/DA module Part 1: Getting the Required Information"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957.webp\" alt=\"\" class=\"wp-image-3115\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957-300x300.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957-150x150.webp 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957-768x768.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957-750x750.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957-400x400.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/effc81f2-def4-45e8-9f29-55c129eca957-250x250.webp 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In this two part series guide on how to create a library for PCF8591 AD\/DA (Analog to Digital\/ Digital to Analog) that can be used with any microcontroller (STM32F4 in this case).<\/p>\n\n\n\n<p>In this guide, 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<h2 class=\"wp-block-heading\">1. Gathering the Required Information:<\/h2>\n\n\n\n<p>Since this guide focuses on how to create library for the module, we shall start from the datasheet.<\/p>\n\n\n\n<p>The datasheet can be found <a href=\"https:\/\/www.nxp.com\/docs\/en\/data-sheet\/PCF8591.pdf\" data-type=\"link\" data-id=\"https:\/\/www.nxp.com\/docs\/en\/data-sheet\/PCF8591.pdf\">here<\/a> or by simply googling PCF8591 datasheet.<\/p>\n\n\n\n<p>From the datasheet:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"846\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-1024x846.jpg\" alt=\"\" class=\"wp-image-3116\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-1024x846.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-300x248.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-768x635.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-1536x1270.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-2048x1693.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-1150x951.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-750x620.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-400x331.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-01-30-250x207.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Control byte to choose the ADC mode and enable the DAC or not.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-979x1024.jpg\" alt=\"\" class=\"wp-image-3117\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-979x1024.jpg 979w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-287x300.jpg 287w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-768x803.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-1469x1536.jpg 1469w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-1150x1202.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-750x784.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-400x418.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56-250x261.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-04-56.jpg 1534w\" sizes=\"(max-width: 979px) 100vw, 979px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>DAC section:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-814x1024.jpg\" alt=\"\" class=\"wp-image-3118\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-814x1024.jpg 814w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-239x300.jpg 239w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-768x966.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-1221x1536.jpg 1221w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-1150x1446.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-750x943.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-400x503.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59-250x314.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-06-59.jpg 1538w\" sizes=\"(max-width: 814px) 100vw, 814px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>From the dynamics characteristics, we can find the maximum clock frequency of 100KHz for the I2C bus as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"787\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-1024x787.jpg\" alt=\"\" class=\"wp-image-3119\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-1024x787.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-300x231.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-768x590.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-1536x1181.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-2048x1574.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-1150x884.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-750x576.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-400x307.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-07-52-250x192.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The ADC reading sequence and DAC write sequence:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"706\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-1024x706.jpg\" alt=\"\" class=\"wp-image-3120\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-1024x706.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-300x207.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-768x529.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-1536x1059.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-1150x793.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-750x517.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-400x276.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50-250x172.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-09-50.jpg 1892w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Since we get all the needed, we can start developing the library.<\/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\"><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>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\"><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<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<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"788\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-1024x788.jpg\" alt=\"\" class=\"wp-image-3121\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-1024x788.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-300x231.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-768x591.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-1536x1183.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-2048x1577.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-1150x885.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-750x577.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-400x308.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_06-47-37-250x192.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\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\"><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>Select the MCU:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><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=\"813\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-813x1024.jpg\" alt=\"\" class=\"wp-image-3122\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-813x1024.jpg 813w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-238x300.jpg 238w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-768x968.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-750x945.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-400x504.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13-250x315.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-28_17-04-13.jpg 984w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/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\"><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>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\"><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>Next Enable I2C1 as following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><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>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=\"865\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-865x1024.jpg\" alt=\"\" class=\"wp-image-3123\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-865x1024.jpg 865w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-254x300.jpg 254w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-768x909.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-750x887.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-400x473.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08-250x296.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/12\/2024-12-29_07-17-08.jpg 1146w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/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\"><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>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\"><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>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>In part 2, we start developing the library.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude09 <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this two part series guide on how to create a library for PCF8591 AD\/DA (Analog to Digital\/ Digital to Analog) that can be used with any microcontroller (STM32F4 in this case). In this guide, we shall cover the following: 1. Gathering the Required Information: Since this guide focuses on how to create library for [&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-3114","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\/3114"}],"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=3114"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3114\/revisions"}],"predecessor-version":[{"id":3124,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3114\/revisions\/3124"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}