{"id":5019,"date":"2021-02-18T06:45:49","date_gmt":"2021-02-18T06:45:49","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=5019"},"modified":"2022-11-23T10:49:26","modified_gmt":"2022-11-23T05:19:26","slug":"stm32-lecture-59-exercise-coding-part-1","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/","title":{"rendered":"STM32 I2C Lecture 59 &#8211; Exercise: Coding Part 1"},"content":{"rendered":"<div class=\"boldgrid-section color4-background-color color-4-text-contrast bg-background-color\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 50px; padding-bottom: 0px;\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\"><\/div>\n<div class=\"col-md-10 col-xs-12 col-sm-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; border-width: 0px; font-size: 33px; line-height: 50px;\"><span style=\"color: #000080;\">Exercise: Coding Part 1<\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/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;\">Now let\u2019s implement the I2C slave exercise.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>Steps of implementation:<\/b><\/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 style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Create the new source file: Copy the old source file and paste it in the src section. Then change the name to 013i2c_slave_tx_string.c, as shown in Figure 1.<\/span><\/li>\n<\/ol>\n<figure id=\"attachment_5021\" aria-describedby=\"caption-attachment-5021\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\" wp-image-5021\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-1.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-768x411.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-1024x548.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-800x428.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1-1200x642.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5021\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Renaming the file.<\/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. Exclude the old file from the build (Figure 2).<\/span><\/p>\n<figure id=\"attachment_5024\" aria-describedby=\"caption-attachment-5024\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\" wp-image-5024\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-2.png\" alt=\"\" width=\"741\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-2-1200x640.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5024\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Excluding the old file from the build.<\/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;\">3. Now let\u2019s modify this code according to the need of our exercise.<\/span><\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">&nbsp;a. First, remove all the semi hosting related codes shown in Figure 3.<\/span><\/p>\n<figure id=\"attachment_5025\" aria-describedby=\"caption-attachment-5025\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\" wp-image-5025\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-3.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-3-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5025\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Code for semi-hosting.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">b. GPIO_ButtonInit(), I2C1_GPIOInits(), I2C1_Inits() and I2C IRQ configuration functions shown in Figure 4 are required so keep it as it is.<\/span><\/p>\n<figure id=\"attachment_5026\" aria-describedby=\"caption-attachment-5026\" style=\"width: 740px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5026\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-4.png\" alt=\"\" width=\"740\" height=\"394\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4.png 1915w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-4-1200x639.png 1200w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><figcaption id=\"caption-attachment-5026\" class=\"wp-caption-text\">Figure 4. Function call for GPIO_ButtonInit(), I2C1_GPIOInits(), I2C1_Inits() and I2C IRQ configuration functions.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">Peripheral control, manage ACKing functions in Figure 5 are required.<\/span><\/p>\n<figure id=\"attachment_5027\" aria-describedby=\"caption-attachment-5027\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5027\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-5.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-5-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5027\" class=\"wp-caption-text\">Figure 5. Call for peripheral control, manage ACKing functions.<\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">c. Remove the entire while loop shown in Figure 6.<\/span><\/p>\n<figure id=\"attachment_5028\" aria-describedby=\"caption-attachment-5028\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5028\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-6.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6.png 1915w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-6-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5028\" class=\"wp-caption-text\">Figure 6. Code to receive the data from the STM32 master.<\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">d. Keep the handlers and application callback shown in Figure 7 as it is.<\/span><\/p>\n<figure id=\"attachment_5029\" aria-describedby=\"caption-attachment-5029\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5029\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-7.png\" alt=\"\" width=\"741\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7.png 1915w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-300x161.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-768x411.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-1024x548.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-500x268.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-800x428.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-7-1200x642.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5029\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Handlers and application callback functions.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">e. Remove the code inside the application callback function (Figure 8).<\/span><\/p>\n<figure id=\"attachment_5031\" aria-describedby=\"caption-attachment-5031\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5031\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-8.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-8-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5031\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Application callback function.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">f. For the I2C1_GPIOInits(), make sure that the pull-up is activated (Figure 9).<\/span><\/p>\n<figure id=\"attachment_5032\" aria-describedby=\"caption-attachment-5032\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5032\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-9.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-9-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5032\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. I2C1_GPIOInits() function.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">g. Remove the code shown in Figure 10.<\/span><\/p>\n<figure id=\"attachment_5033\" aria-describedby=\"caption-attachment-5033\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5033\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-10.png\" alt=\"\" width=\"741\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10.png 1915w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-300x161.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-768x412.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-1024x549.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-600x322.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-500x268.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-400x215.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-800x429.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-10-1200x644.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5033\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Code to make initialise_monitor_handles() function as extern.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">h. rxComplt flag variable (Figure 11) is not required. Let\u2019s remove that.<\/span><\/p>\n<figure id=\"attachment_5034\" aria-describedby=\"caption-attachment-5034\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5034\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-11.png\" alt=\"\" width=\"741\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-11-1200x640.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5034\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Declaring and initializing the rxComplt flag.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">i. In this case, the slave address is 0x68. Therefore, remove the MY_ADDR macro shown in Figure 12.<\/span><\/p>\n<figure id=\"attachment_5035\" aria-describedby=\"caption-attachment-5035\" style=\"width: 740px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5035\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-12.png\" alt=\"\" width=\"740\" height=\"393\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-768x408.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-1024x544.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-400x212.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-800x425.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-12-1200x637.png 1200w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><figcaption id=\"caption-attachment-5035\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Code to define MY_ADDR macro.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">j. Change the name of the buffer to Tx_buf, and let&#8217;s have some message in it, as shown in Figure 13. Ensure that the total number of bytes in a message doesn&#8217;t cross the 32 bytes, which is the limitation of the Arduino code&#8217;s wire library. The way of transmitting or receiving more than 32 bytes will be discussed later in this article. For the time being, just make sure that the length doesn&#8217;t cross 32 bytes.<\/span><\/p>\n<figure id=\"attachment_5036\" aria-describedby=\"caption-attachment-5036\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5036\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-13.png\" alt=\"\" width=\"742\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-13-1200x640.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5036\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 13. Declaring and initializing Tx_buf.<\/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;\">4. Now let\u2019s investigate what we are doing in the I2C1_Inits(). In I2C1_Inits(), I2C_Config.I2C_DeviceAddress field (Figure 14) is very important, and the slave address should be configured here. The slave address is stored in MY_ADDR macro, which is not yet defined. Now let\u2019s define that, as shown in Figure 15. MY_ADDR is nothing but the slave ADDR. Here the slave address is 0x68.<\/span><\/p>\n<figure id=\"attachment_5037\" aria-describedby=\"caption-attachment-5037\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5037\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-14.png\" alt=\"\" width=\"741\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-300x161.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-768x411.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-1024x548.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-500x268.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-800x428.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-14-1200x642.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5037\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 14. I2C1_Inits() function.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_5038\" aria-describedby=\"caption-attachment-5038\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5038\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-15.png\" alt=\"\" width=\"741\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-15-1200x639.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5038\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 15. Defining MY_ADDR macro.<\/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;\">5. You can see that in the main code, the IRQs are enabled (Figure 16). But the interrupt control bits in the I2C CR2 register are not enabled. You have to enable those control bits now because without enabling those interrupt control bits, it is impossible to generate the interrupt for I2C events or I2C errors.<\/span><\/p>\n<figure id=\"attachment_5039\" aria-describedby=\"caption-attachment-5039\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5039\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-16.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-16-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5039\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 16. Code to enable the IRQs.<\/span><\/figcaption><\/figure>\n<p>&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;\">Now let\u2019s create one API for enabling the interrupt control bits in the I2C CR2 register, as shown in Figure 17.<\/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\u2019s give the API name as I2C_SlaveEnableDisableCallbackEvents(), and it takes two arguments. One is handle, and another is ENABLE.<\/span><\/p>\n<figure id=\"attachment_5040\" aria-describedby=\"caption-attachment-5040\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5040\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-17.png\" alt=\"\" width=\"742\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-768x408.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-1024x544.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-800x425.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-17-1200x638.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5040\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 17. API for enabling the interrupt control bits in the I2C CR2 register.<\/span><\/figcaption><\/figure>\n<p>&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;\">6. Copy the I2C_SlaveEnableDisableCallbackEvents() API, then paste it in the other peripheral control APIs section of the driver.h file and make changes to the arguments, as shown in Figure 18.<\/span><\/p>\n<figure id=\"attachment_5041\" aria-describedby=\"caption-attachment-5041\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5041\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-18.png\" alt=\"\" width=\"742\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-18-1200x640.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5041\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 18. Prototype of I2C_SlaveEnableDisableCallbackEvents() API.<\/span><\/figcaption><\/figure>\n<p>&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;\">7. Now let\u2019s implement the I2C_SlaveEnableDisableCallbackEvents() function in the driver.c file as follows:<\/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 EnorDi variable is equal to ENABLE, then you must enable the control bits ITEVTEN, ITBUFEN, and ITERREN. Otherwise, you have to disable them (Figure 19).<\/span><\/p>\n<figure id=\"attachment_5043\" aria-describedby=\"caption-attachment-5043\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5043\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-19.png\" alt=\"\" width=\"741\" height=\"398\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-300x161.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-768x412.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-1024x550.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-600x322.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-500x268.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-400x215.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-800x429.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-19-1200x644.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5043\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 19. Implementation of I2C_SlaveEnableDisableCallbackEvents() function.<\/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;\">8. Go to the application. I2C_SlaveEnableDisableCallbackEvents() API enables the callback events. After that, the peripheral will be enabled. Then the ACK will be enabled. After enabling a peripheral and ACK, the slave just hangs in the infinite while loop, as shown in Figure 20.<\/span><\/p>\n<figure id=\"attachment_5044\" aria-describedby=\"caption-attachment-5044\" style=\"width: 740px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5044\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-20.png\" alt=\"\" width=\"740\" height=\"394\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-20-1200x638.png 1200w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><figcaption id=\"caption-attachment-5044\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 20. Infinite while loop to hang the slave code.<\/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;\">9. Whenever a request is received, or events happen, the application event callback will be called. Now let\u2019s implement the application event callback function (Figure 21).&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 style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">If the application event (AppEv) is equal to the I2C event data request (I2C_EV_DATA_REQ), then that means the master wants some data, and the slave has to send it.&nbsp;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">If the application event (AppEv) is equal to I2C event data receive (I2C_EV_DATA_RCV), then that means the data is waiting for the slave to read, and the slave has to read it.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">The application event (AppEv) will be equal to I2C error Ack failure (I2C_ERROR_AF) only during slave transmission. When the AppEv becomes equal to I2C_ERROR_AF, it means that the master has sent the NACK. Therefore, the slave should understand that the master doesn\u2019t need more data.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400; color: #000000;\">The application event (AppEv) will be equal to the I2C event stop (I2C_EV_STOP) only during slave reception. When the AppEv becomes equal to I2C_EV_STOP, it means that the master has ended the I2C communication with the slave. Therefore, the slave should conclude that the master has ended the I2C communication with it.<\/span><\/li>\n<\/ol>\n<figure id=\"attachment_5045\" aria-describedby=\"caption-attachment-5045\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5045\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-21.png\" alt=\"\" width=\"742\" height=\"394\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-768x408.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-1024x544.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-400x212.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-800x425.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-21-1200x637.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5045\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 21. Implementation of application event callback function.<\/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;\">10. Procedure to read the data from the STM32 slave:<\/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 style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Master sends command code 0x51 to read the length (1-byte information) of the data from the slave.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Master sends command code 0x52 to read the complete data from the slave.<\/span><\/li>\n<\/ol>\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;\">Now let\u2019s code according to the above procedure.<\/span><\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">a. First, the master sends a command code to the slave, which is nothing but reading for the slave (or slave data receive). So, whenever data receive happens, the slave stores the command code (Figure 22).<\/span><\/p>\n<p class=\"\" style=\"padding-left: 30px; 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 commandCode variable used to store the command code must be a global variable because the application event callback function exists without hanging anywhere. Therefore, you can\u2019t create that variable locally. Now let\u2019s create a commandCode variable globally, as shown in Figure 22.<\/span><\/p>\n<figure id=\"attachment_5046\" aria-describedby=\"caption-attachment-5046\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5046\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-22.png\" alt=\"\" width=\"742\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-22-1200x640.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5046\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 22. Code to store the command code received by the slave.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"padding-left: 30px; 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;\">b. When the master does read transactions, that is actually a data request for the slave. So, the first if block in Figure 21 will get executed. If the command code received is equal to 0x51, then send the length information to the master. The length information can be sent to the master using I2C_SlaveSendData() API (Figure 23). I2C_SlaveSendData() API takes two parameters, one is handle, and another is data. Here the data is nothing but the length of Tx_buf (strlen(Tx_buf)).&nbsp;<\/span><\/p>\n<p class=\"\" style=\"padding-left: 30px; 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 command code is equal to 0x52, then send the contents of Tx buf. To send the contents of Tx_buf, again use I2C_SlaveSendData() API. Here instead of length, you have to use Tx_buf[Cnt++] as a second parameter. Now let\u2019s define the Cnt variable. This variable must be global. Otherwise, you can also use a static keyword while defining the Cnt variable, as shown in Figure 23. Static variables are a kind of global variable since the memory for these variables will be allocated in a global space instead of a stack. That\u2019s why even if the application event callback function exits, memory for these variables will not be deallocated, and you can access it from the functions that are called inside the callback function. Even though they are in a global space, you can\u2019t access these variables from other functions because we have used a static keyword. Static means private to that function.<\/span><\/p>\n<figure id=\"attachment_5048\" aria-describedby=\"caption-attachment-5048\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5048\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-23.png\" alt=\"\" width=\"741\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-23-1200x640.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5048\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 23. I2C event data request.<\/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;\">c. Once the command code 0x51 is received, and the slave has sent the length information, the acknowledgement failure happens to indicate the completion of a slave TXing. When an acknowledgement failure occurs, invalidate the commandCode variable and reset the Cnt variable, as shown in Figure 24.<\/span><\/p>\n<figure id=\"attachment_5052\" aria-describedby=\"caption-attachment-5052\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5052\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-24.png\" alt=\"\" width=\"742\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-24-1200x640.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5052\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 24. Tasks to be performed when ACK failure happens.<\/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;\">All these are the ways in which the slave responds to the various I2C transactions, and remember that all the steps that are coded above depend upon different types of I2C transactions used in your application. The application callback event function here is coded purely with respect to the data read, and data write transactions.<\/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;\">For example, first, the master generates I2C transactions to read the one-byte length information. So, first, the sending command to slave event will be generated. Therefore, in the slave code, the if condition shown in Figure 25 will be executed, and the slave stores the command code, which is received. This is nothing but a write I2C transaction, which results in a read for the slave.<\/span><\/p>\n<figure id=\"attachment_5053\" aria-describedby=\"caption-attachment-5053\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5053\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-25.png\" alt=\"\" width=\"742\" height=\"394\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-768x408.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-1024x544.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-400x212.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-800x425.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-25-1200x637.png 1200w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><figcaption id=\"caption-attachment-5053\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 25. Data receive (or read transaction) in the slave.<\/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;\">Master reading response from the slave is nothing but a read transaction. In this read transaction, the master reads the length information from the slave. Read results in data request in the slave. Therefore, the if block shown in Figure 26 will be executed, and master will read the length since it has already sent the command code as 0x51.<\/span><\/p>\n<figure id=\"attachment_5054\" aria-describedby=\"caption-attachment-5054\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5054\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-26.png\" alt=\"\" width=\"741\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-26-1200x640.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5054\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 26. Data request in the slave.<\/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;\">After that master generates two more I2C transactions to read length bytes of data from the slave. For that, first, perform a write transaction. The master sends command code 0x52. Again, the if block in Figure 25 will get executed, and now the command code will be 0x52. Then a read transaction is initiated by the master, and the block shown in Figure 27 will be executed, which is nothing but sending the contents of Tx_buf. Whenever TXE is set, the if block in Figure 27 will get executed, and the slave sends the data byte by byte to the master. When the transmission ends, the ACK failure will be generated, and the block in Figure 28 will get executed.<\/span><\/p>\n<figure id=\"attachment_5055\" aria-describedby=\"caption-attachment-5055\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5055\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-27.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-27-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5055\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 27. Code to read length bytes of data from the slave.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_5056\" aria-describedby=\"caption-attachment-5056\" style=\"width: 741px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-5056\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/02\/Figure-28.png\" alt=\"\" width=\"741\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28.png 1919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-28-1200x641.png 1200w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><figcaption id=\"caption-attachment-5056\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 28. Code to handle ACK failure.<\/span><\/figcaption><\/figure>\n<\/div>\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\" style=\"padding-left: 120px;\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Exercise: Coding Part 1 &nbsp; &nbsp; Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source file and paste it in the src section. Then change the name to 013i2c_slave_tx_string.c, as shown in Figure 1. &nbsp; 2. Exclude the old file from the build (Figure 2). [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5021,"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-5019","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>STM32 I2C Lecture 59 - Exercise: Coding Part 1<\/title>\n<meta name=\"description\" content=\"Exercise: Coding Part 1 Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source\" \/>\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\/stm32-lecture-59-exercise-coding-part-1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32 I2C Lecture 59 - Exercise: Coding Part 1\" \/>\n<meta property=\"og:description\" content=\"Exercise: Coding Part 1 Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-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=\"2021-02-18T06:45:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-23T05:19:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1917\" \/>\n\t<meta property=\"og:image:height\" content=\"1025\" \/>\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=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"STM32 I2C Lecture 59 &#8211; Exercise: Coding Part 1\",\"datePublished\":\"2021-02-18T06:45:49+00:00\",\"dateModified\":\"2022-11-23T05:19:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/\"},\"wordCount\":1950,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/Figure-1.png\",\"keywords\":[\"STM32 I2C Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/\",\"name\":\"STM32 I2C Lecture 59 - Exercise: Coding Part 1\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/Figure-1.png\",\"datePublished\":\"2021-02-18T06:45:49+00:00\",\"dateModified\":\"2022-11-23T05:19:26+00:00\",\"description\":\"Exercise: Coding Part 1 Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/Figure-1.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/Figure-1.png\",\"width\":1917,\"height\":1025,\"caption\":\"Figure 1. Renaming the file.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-lecture-59-exercise-coding-part-1\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32 I2C Lecture 59 &#8211; Exercise: Coding 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":"STM32 I2C Lecture 59 - Exercise: Coding Part 1","description":"Exercise: Coding Part 1 Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source","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\/stm32-lecture-59-exercise-coding-part-1\/","og_locale":"en_US","og_type":"article","og_title":"STM32 I2C Lecture 59 - Exercise: Coding Part 1","og_description":"Exercise: Coding Part 1 Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source","og_url":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2021-02-18T06:45:49+00:00","article_modified_time":"2022-11-23T05:19:26+00:00","og_image":[{"width":1917,"height":1025,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-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":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"STM32 I2C Lecture 59 &#8211; Exercise: Coding Part 1","datePublished":"2021-02-18T06:45:49+00:00","dateModified":"2022-11-23T05:19:26+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/"},"wordCount":1950,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1.png","keywords":["STM32 I2C Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/","url":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/","name":"STM32 I2C Lecture 59 - Exercise: Coding Part 1","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1.png","datePublished":"2021-02-18T06:45:49+00:00","dateModified":"2022-11-23T05:19:26+00:00","description":"Exercise: Coding Part 1 Now let\u2019s implement the I2C slave exercise. Steps of implementation: Create the new source file: Copy the old source","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/02\/Figure-1.png","width":1917,"height":1025,"caption":"Figure 1. Renaming the file."},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/stm32-lecture-59-exercise-coding-part-1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"STM32 I2C Lecture 59 &#8211; Exercise: Coding 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\/5019","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=5019"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/5019\/revisions"}],"predecessor-version":[{"id":12599,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/5019\/revisions\/12599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/5021"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=5019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=5019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=5019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}