{"id":4023,"date":"2020-12-03T08:32:21","date_gmt":"2020-12-03T08:32:21","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=4023"},"modified":"2023-09-06T11:58:46","modified_gmt":"2023-09-06T06:28:46","slug":"implementation-of-i2c-init-api-part-1","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/","title":{"rendered":"STM32 I2C Lecture 14: Implementation of I2C init API: Part 1"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 50px; padding-bottom: 50px;\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; border-width: 0px; font-size: 38px; line-height: 55px;\"><span style=\"color: #000080;\">Implementation of I2C init API: Part 1<\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-16\" style=\"border-style: solid; border-width: 0px 0px 3px; color: rgba(11, 34, 151, 0.9); margin-top: -25px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<div class=\"row bg-editor-hr-wrap\">\n<hr>\n<\/div>\n<div class=\"mceTemp\"><\/div>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this article, let\u2019s code I2C_Init. Let\u2019s discuss the things that need to be configured in the I2C registers.&nbsp;<\/span><\/p>\n<ol class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">To control the acking, you need to configure the ACK (10<\/span><span style=\"font-weight: 400;\">th<\/span><span style=\"font-weight: 400;\">&nbsp; bit) bit of the CR1 register, as shown in Figure 1.<\/span><\/span><\/li>\n<\/ol>\n<figure id=\"attachment_4026\" aria-describedby=\"caption-attachment-4026\" style=\"width: 701px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\" wp-image-4026\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-1-1.png\" alt=\"\" width=\"701\" height=\"374\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png 1913w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1-1200x640.png 1200w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><figcaption id=\"caption-attachment-4026\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Code for configuring ACK of CR1 register.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">2. Configure the FREQ field of the CR2 register. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The FREQ bits must be configured with the APB clock frequency value. That means the exact clock frequency of the APB1 bus must be calculated. We already know that in our case, it is 16. But it need not be the same always. The user may change this value. Therefore, it is required to calculate the FREQ field. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s create a small function to calculate the APB1 bus clock&#8217;s value, as shown in Figure 2.<\/span><\/p>\n<figure id=\"attachment_4027\" aria-describedby=\"caption-attachment-4027\" style=\"width: 699px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\" wp-image-4027\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-2-1.png\" alt=\"\" width=\"699\" height=\"370\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-768x407.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-1024x543.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-600x318.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-500x265.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-400x212.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-800x424.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-2-1-1200x636.png 1200w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><figcaption id=\"caption-attachment-4027\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Function to calculate the APB1 bus clock&#8217;s value.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Refer to the clock tree shown in Figure 3 to know how the PCLK1 is calculated. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">To calculate the PCLK1, First, find out the source by reading the RCC registers. <\/span><span style=\"font-weight: 400; color: #000000;\">After that, calculate the AHB prescaler and APB1 prescaler. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The value of PCLK1 depends on the clock source, which means the system clock, and it is decided depending on the HSE, HSI, PLLCLK, PLLR, etc. In our case, the system clock is HSI (16MHz), which is then divided by the AHB prescaler to get the AHB clock.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"> To obtain the APB1 clock, divide the AHB clock by APB1 prescaler, and then the APB1 clock is delivered to the APB1 peripherals where I2C is connected.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4028\" aria-describedby=\"caption-attachment-4028\" style=\"width: 726px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\" wp-image-4028\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-3-1.png\" alt=\"\" width=\"726\" height=\"377\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1.png 1462w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-300x156.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-768x399.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-1024x532.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-600x312.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-120x62.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-500x260.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-200x104.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-400x208.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-800x416.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-3-1-1200x624.png 1200w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><figcaption id=\"caption-attachment-4028\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Clock tree<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the clock configuration registers of RCC, refer to the bit numbers 2 and 3 (Figure 4).&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4029\" aria-describedby=\"caption-attachment-4029\" style=\"width: 762px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4029\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-4..png\" alt=\"\" width=\"762\" height=\"142\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4..png 1348w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-300x56.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-768x143.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-1024x191.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-600x112.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-120x22.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-500x93.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-200x37.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-400x74.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-800x149.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-4.-1200x223.png 1200w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><figcaption id=\"caption-attachment-4029\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Bit 2 and 3 of Clock configuration registers of RCC.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Calculate the values of bits 2 and 3 to determine which clock source is used as the system clock. Now let\u2019s write the code for finding the clock source.<\/span><\/p>\n<ul class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400; color: #000000;\">Create a clksrc variable of type uint8_t.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400; color: #000000;\">Read the values of bits 3 and 2 of the RCC_CFGR register to the clksrc variable. This is done by using clksrc = (RCC -&gt; CFGR&nbsp; &gt;&gt; 2) statement. Here the right shift by two is done to bring the bit number second and third to the bit position zero and one.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400; color: #000000;\">Mask the first two bits with the bitwise &amp; operator. clksrc = ((RCC -&gt; CFGR &gt;&gt; 2) &amp; 0x3) will mask all other bits except the bit number zero and bit number one, where the value is stored.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400; color: #000000;\">Then select the system clock depending on the value stored in the clksrc variable, as shown in Figure 5.<\/span><\/li>\n<\/ul>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4030\" aria-describedby=\"caption-attachment-4030\" style=\"width: 1917px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4030 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-5.png\" alt=\"Implementation of I2C init API: Part 1\" width=\"1917\" height=\"1191\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-300x186.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-768x477.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-1024x636.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-600x373.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-320x200.png 320w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-120x75.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-500x311.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-200x124.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-400x249.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-800x497.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-5-1200x746.png 1200w\" sizes=\"(max-width: 1917px) 100vw, 1917px\" \/><figcaption id=\"caption-attachment-4030\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Code for finding the system clock.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Find out the value of AHB prescaler. This value is decided by the bit fields 4 to 7 of the RCC_CFGR register, and the field name is HPRE, the AHB prescaler. If the system clock is less than eight, then the system clock is not divided; else, the system clock will be divided according to the information in Figure 6.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4032\" aria-describedby=\"caption-attachment-4032\" style=\"width: 723px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4032\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-6.png\" alt=\"Implementation of I2C init API: Part 1\" width=\"723\" height=\"305\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6.png 1349w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-300x126.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-768x323.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-1024x431.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-600x253.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-120x51.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-500x211.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-200x84.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-400x168.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-800x337.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-6-1200x505.png 1200w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><figcaption id=\"caption-attachment-4032\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. AHB prescaler value.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Read the value of HPRE into a temp variable using temp = (RCC -&gt; CFGR &gt;&gt; 4) statement. Then temp = ((RCC -&gt; CFGR &gt;&gt; 4) &amp; 0xF) will mask all other bits except the first four bits. Select the AHB prescaler value from AHB_PreScaler [] array depending on the temp, as shown in Figure 7. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Where AHB_PreScaler is a variable of type array, which holds all the division factors.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4033\" aria-describedby=\"caption-attachment-4033\" style=\"width: 726px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4033\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-7.png\" alt=\"Implementation of I2C init API: Part 1\" width=\"726\" height=\"388\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7.png 1911w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-7-1200x641.png 1200w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><figcaption id=\"caption-attachment-4033\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Code for calculating AHB prescaler.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We already found out the value of AHB prescaler. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The next task is to find out the APB1 prescaler. For this, you have to refer to the 10, 11, and 12th bit of the RCC_CFGR register shown in Figure 8.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"> If the PPRE1 field&#8217;s value is less than four, then the AHB clock is not divided; otherwise, the AHB clock will be divided according to the division factors in Figure 8.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4034\" aria-describedby=\"caption-attachment-4034\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4034\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-8.png\" alt=\"Implementation of I2C init API: Part 1\" width=\"741\" height=\"220\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8.png 1383w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-300x89.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-768x228.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-1024x304.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-600x178.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-120x36.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-500x149.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-200x59.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-400x119.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-800x238.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-8-1200x357.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-4034\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. APB1 prescaler value.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Read the value of PPRE1 into a temp variable using temp = (RCC -&gt; CFGR &gt;&gt; 10) statement. Then temp = ((RCC -&gt; CFGR &gt;&gt; 10) &amp; 0x7) will mask all other bits except the first three bits. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Select the APB1 prescaler value from APB1_PreScaler [] array depending on the temp value, as shown in Figure 9. Where APB1_PreScaler is a variable of type array, which holds all the division factors for PPRE1.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4035\" aria-describedby=\"caption-attachment-4035\" style=\"width: 701px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4035\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-9.png\" alt=\"Implementation of I2C init API: Part 1\" width=\"701\" height=\"371\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-768x407.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-1024x543.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-600x318.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-500x265.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-400x212.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-800x424.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-9-1200x636.png 1200w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><figcaption id=\"caption-attachment-4035\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Code for calculating APB1 prescaler.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Finally, the pclk1 can be calculated using pclk1 = (SystemClk \/ ahbp) \/ apb1p, and then the pclk1 value is returned (Figure 10).<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4036\" aria-describedby=\"caption-attachment-4036\" style=\"width: 729px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4036\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2020\/12\/Figure-10.png\" alt=\"Implementation of I2C init API: Part 1\" width=\"729\" height=\"386\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-768x407.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-1024x543.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-600x318.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-500x265.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-400x212.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-800x424.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-10-1200x636.png 1200w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><figcaption id=\"caption-attachment-4036\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Code for calculating PCLK1 value.<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The program discussed till now is the generic function to calculate the value of PCLK1, and a similar function can be created for PCLK2\u2014here no need to create a PCLK2 function since the I2C is not hanging on other buses. Let&#8217;s continue it in the <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"http:\/\/fastbitlab.com\/stm32-i2c-lecture-15-implementation-i2c-init-api-part-2\/\" target=\"_blank\" rel=\"noopener\">following article<\/a><\/span>.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 18px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses,<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: Roboto; font-weight: 400; font-size: 17px; line-height: 25px;\" data-font-family=\"Roboto\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">Click here:<\/span>&nbsp;<span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\">https:\/\/fastbitlab.com\/course1<\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; Implementation of I2C init API: Part 1 &nbsp; &nbsp; In this article, let\u2019s code I2C_Init. Let\u2019s discuss the things that need to be configured in the I2C registers.&nbsp; To control the acking, you need to configure the ACK (10th&nbsp; bit) bit of the CR1 register, as shown in Figure 1. &nbsp; 2. Configure [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[23],"class_list":["post-4023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-stm32-i2c-lectures","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>I2C Init API Implementation: Configuring I2C Registers - Part 1<\/title>\n<meta name=\"description\" content=\"Implementation of I2C init API: Part 1. Learn how to initialize the I2C interface by configuring crucial settings in this detailed guide. Dive\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"I2C Init API Implementation: Configuring I2C Registers - Part 1\" \/>\n<meta property=\"og:description\" content=\"Implementation of I2C init API: Part 1. Learn how to initialize the I2C interface by configuring crucial settings in this detailed guide. Dive\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-03T08:32:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-06T06:28:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1913\" \/>\n\t<meta property=\"og:image:height\" content=\"1021\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"STM32 I2C Lecture 14: Implementation of I2C init API: Part 1\",\"datePublished\":\"2020-12-03T08:32:21+00:00\",\"dateModified\":\"2023-09-06T06:28:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/\"},\"wordCount\":931,\"commentCount\":17,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Figure-1-1.png\",\"keywords\":[\"STM32 I2C Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/\",\"name\":\"I2C Init API Implementation: Configuring I2C Registers - Part 1\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Figure-1-1.png\",\"datePublished\":\"2020-12-03T08:32:21+00:00\",\"dateModified\":\"2023-09-06T06:28:46+00:00\",\"description\":\"Implementation of I2C init API: Part 1. Learn how to initialize the I2C interface by configuring crucial settings in this detailed guide. Dive\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Figure-1-1.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/Figure-1-1.png\",\"width\":1913,\"height\":1021,\"caption\":\"Figure 1. Code for configuring ACK of CR1 register.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/implementation-of-i2c-init-api-part-1\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32 I2C Lecture 14: Implementation of I2C init API: Part 1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"I2C Init API Implementation: Configuring I2C Registers - Part 1","description":"Implementation of I2C init API: Part 1. Learn how to initialize the I2C interface by configuring crucial settings in this detailed guide. Dive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/","og_locale":"en_US","og_type":"article","og_title":"I2C Init API Implementation: Configuring I2C Registers - Part 1","og_description":"Implementation of I2C init API: Part 1. Learn how to initialize the I2C interface by configuring crucial settings in this detailed guide. Dive","og_url":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2020-12-03T08:32:21+00:00","article_modified_time":"2023-09-06T06:28:46+00:00","og_image":[{"width":1913,"height":1021,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"STM32 I2C Lecture 14: Implementation of I2C init API: Part 1","datePublished":"2020-12-03T08:32:21+00:00","dateModified":"2023-09-06T06:28:46+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/"},"wordCount":931,"commentCount":17,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png","keywords":["STM32 I2C Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/","url":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/","name":"I2C Init API Implementation: Configuring I2C Registers - Part 1","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png","datePublished":"2020-12-03T08:32:21+00:00","dateModified":"2023-09-06T06:28:46+00:00","description":"Implementation of I2C init API: Part 1. Learn how to initialize the I2C interface by configuring crucial settings in this detailed guide. Dive","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2020\/12\/Figure-1-1.png","width":1913,"height":1021,"caption":"Figure 1. Code for configuring ACK of CR1 register."},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/implementation-of-i2c-init-api-part-1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"STM32 I2C Lecture 14: Implementation of I2C init API: Part 1"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/4023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=4023"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/4023\/revisions"}],"predecessor-version":[{"id":12525,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/4023\/revisions\/12525"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/4026"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=4023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=4023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=4023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}