{"id":4946,"date":"2021-01-23T04:57:06","date_gmt":"2021-01-23T04:57:06","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=4946"},"modified":"2022-11-23T10:36:36","modified_gmt":"2022-11-23T05:06:36","slug":"stm32-i2c-lecture-57-i2c-slave-support-in-driver","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/","title":{"rendered":"STM32 I2C Lecture 57: I2C slave support in driver"},"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; 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=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\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; font-size: 32px; border-width: 0px; line-height: 47px;\"><span style=\"color: #000080;\">I2C slave support in driver<\/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<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 class=\"row bg-editor-hr-wrap\">\n<hr>\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 all the callback events for slave transmitter and slave receiver.<\/span><\/p>\n<p class=\"\" style=\"font-size: 24px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 35px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline;\"><span style=\"color: #000080;\"><b>Steps:<\/b><\/span><\/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;\">1. Go to the event IRQ handling section of the driver file shown in Figure 1.<\/span><\/p>\n<figure id=\"attachment_4948\" aria-describedby=\"caption-attachment-4948\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-4948\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-1-7.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"398\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-768x411.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-1024x548.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-800x428.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7-1200x642.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4948\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. I2C_EV_IRQHandling() API.<\/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=\"color: #000000;\">2.&nbsp;<span style=\"font-weight: 400;\">In the TXE event, check for the device mode. If the device is master, then the code in Figure 2 will get executed.<\/span><\/span><\/p>\n<figure id=\"attachment_4949\" aria-describedby=\"caption-attachment-4949\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-4949\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-2-7.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7.png 1921w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-768x408.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-1024x544.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-800x425.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-2-7-1200x638.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4949\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Code to be executed when the device mode is master.<\/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;\">The code to be executed when the device mode is a slave is implemented as follows:<\/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;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">The TXE is nothing but a request for data.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Call the application callback function and send handle and data request event as a parameter of the function, as shown in Figure 3.<\/span><\/li>\n<\/ul>\n<figure id=\"attachment_4951\" aria-describedby=\"caption-attachment-4951\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-4951\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-3-5.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5.png 1921w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-3-5-1200x640.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4951\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Call for the 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;\">Define I2C_EV_DATA_REQ macro in the I2C header (Figure 4).<\/span><\/p>\n<figure id=\"attachment_4952\" aria-describedby=\"caption-attachment-4952\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4952\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-4-5.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"398\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5.png 1915w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-1024x547.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-4-5-1200x641.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4952\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Defining macro I2C_EV_DATA_REQ.<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&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;\">The application callback function is called only if the slave is in transmitter mode. You can check the status register (SR2 shown in Figure 5) to see whether the device is in transmitter mode or receiver mode.<\/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;\"> In status register 2, you will find TRA bit, which helps you understand whether the device is in transmitter mode or slave mode. If the TRA bit is zero, then the device is in receiver mode; if it is set, then the device is in transmitter mode.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_4953\" aria-describedby=\"caption-attachment-4953\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4953\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-5-5.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"422\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5.png 1610w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-300x170.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-768x435.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-1024x580.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-600x340.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-500x283.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-400x227.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-800x453.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-5-5-1200x680.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4953\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. I2C status register 2.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/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;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">First, make sure that the slave is really in transmitter mode by using the if statement (Figure 6). If the TRA is set, then the device will be in transmitter mode, the TXE will also happen, and you can call the application callback function, as shown in Figure 6.<\/span><\/li>\n<\/ul>\n<figure id=\"attachment_4954\" aria-describedby=\"caption-attachment-4954\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4954\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-6-5.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-6-5-1200x639.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4954\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Code to check whether the slave is in transmitter mode or not.<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&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;\">Remember that the TRA bit is influenced by the read-write bit of the address phase.<\/span><\/p>\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=\"color: #000000;\">3.&nbsp;<span style=\"font-weight: 400;\">For the data receive, you have to change the RXNE event.<\/span><\/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;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">The code to be executed when the device is in master mode is shown in Figure 7.<\/span><\/li>\n<\/ul>\n<figure id=\"attachment_4956\" aria-describedby=\"caption-attachment-4956\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4956\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-7-5.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5.png 1915w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-7-5-1200x640.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4956\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Code to be executed when the device is in master mode.<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/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;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Now let\u2019s implement the else part, the code to be executed when the device is in slave mode. <\/span><\/li>\n<\/ul>\n<p class=\"\" style=\"padding-left: 40px; 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;\">First, make sure that the device is in receiver mode by checking the TRA bit of the SR2 register. If TRA is zero, then call the application callback function and send handle and I2C data receive event as a parameter of the function, as shown in Figure 8.<\/span><\/p>\n<figure id=\"attachment_4958\" aria-describedby=\"caption-attachment-4958\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4958\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-8-4.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-8-4-1200x639.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4958\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Code to be executed when the device is in slave receiver mode.<\/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;\">Define I2C_EV_DATA_RCV macro in the I2C header (Figure 9).<\/span><\/p>\n<figure id=\"attachment_4959\" aria-describedby=\"caption-attachment-4959\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4959\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-9-3.png\" alt=\"I2C slave support in driver\" width=\"744\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-768x410.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-1024x546.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-800x427.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-9-3-1200x640.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4959\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Defining macro I2C_EV_DATA_RCV.<\/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=\"color: #000000;\">4.&nbsp;<span style=\"font-weight: 400;\">Implement the ACK failure (Figure 10) in the error IRQ handling. When the ACK failure happens, first, you have to clear the ACK failure and then send the event callback.<\/span><\/span><\/p>\n<figure id=\"attachment_4960\" aria-describedby=\"caption-attachment-4960\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4960\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-10-2.png\" alt=\"Code to handle the ACK failure\" width=\"744\" height=\"398\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-768x411.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-1024x548.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-500x267.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-800x428.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-10-2-1200x642.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4960\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Code to handle the ACK failure.<\/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=\"color: #000000;\">5. <span style=\"font-weight: 400;\">Generate the stop condition in the I2C event IRQ handling (Figure 11) since the stop is an event. When the stop occurs, you have to complete a clear sequence. After completing the clear sequence, call the application callback function for the stop event, as shown in Figure 11. <\/span><\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">The master will not execute the code in Figure 11 since the STOPF is not applicable to the master.<\/span><\/span><\/p>\n<figure id=\"attachment_4961\" aria-describedby=\"caption-attachment-4961\" style=\"width: 743px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4961\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-11-2.png\" alt=\"Code to generate the stop condition\" width=\"743\" height=\"402\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-300x162.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-768x415.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-1024x554.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-600x325.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-120x65.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-500x270.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-200x108.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-400x216.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-800x433.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-11-2-1200x649.png 1200w\" sizes=\"(max-width: 743px) 100vw, 743px\" \/><figcaption id=\"caption-attachment-4961\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Code to generate the stop condition.<\/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=\"color: #000000;\">6.&nbsp;<span style=\"font-weight: 400;\">Compile the code (Figure 12).<\/span><\/span><\/p>\n<figure id=\"attachment_4985\" aria-describedby=\"caption-attachment-4985\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4985\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2021\/01\/Figure-12-2.png\" alt=\"Code compilation\" width=\"744\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2.png 1917w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-600x320.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-12-2-1200x639.png 1200w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption id=\"caption-attachment-4985\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Code compilation.<\/span><\/figcaption><\/figure>\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;\">This completes the slave logic. For the slave, the application has to process the data request, and data receive event.<\/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=\"color: #000000;\">In the following article, let&#8217;s do the Exercise:<\/span> <span style=\"color: #ff6600;\"><a style=\"color: #ff6600; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/exercise-i2c-slave-programming\/\" target=\"_blank\" rel=\"noopener\">I2C slave programming<\/a><\/span>.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 25px;\" 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-size: 17px;\"><span style=\"color: #000000;\">Click here:&nbsp;<\/span><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<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; I2C slave support in driver &nbsp; &nbsp; Now let\u2019s implement all the callback events for slave transmitter and slave receiver. Steps: 1. Go to the event IRQ handling section of the driver file shown in Figure 1. &nbsp; 2.&nbsp;In the TXE event, check for the device mode. If the device is master, then the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4948,"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-4946","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 57: I2C slave support in driver<\/title>\n<meta name=\"description\" content=\"I2C slave support in driver. Let\u2019s implement all the callback events for slave transmitter and slave receiver. Go to the event IRQ handling\" \/>\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-i2c-lecture-57-i2c-slave-support-in-driver\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32 I2C Lecture 57: I2C slave support in driver\" \/>\n<meta property=\"og:description\" content=\"I2C slave support in driver. Let\u2019s implement all the callback events for slave transmitter and slave receiver. Go to the event IRQ handling\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/\" \/>\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-01-23T04:57:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-23T05:06:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"STM32 I2C Lecture 57: I2C slave support in driver\",\"datePublished\":\"2021-01-23T04:57:06+00:00\",\"dateModified\":\"2022-11-23T05:06:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/\"},\"wordCount\":726,\"commentCount\":47,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Figure-1-7.png\",\"keywords\":[\"STM32 I2C Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/\",\"name\":\"STM32 I2C Lecture 57: I2C slave support in driver\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Figure-1-7.png\",\"datePublished\":\"2021-01-23T04:57:06+00:00\",\"dateModified\":\"2022-11-23T05:06:36+00:00\",\"description\":\"I2C slave support in driver. Let\u2019s implement all the callback events for slave transmitter and slave receiver. Go to the event IRQ handling\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Figure-1-7.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Figure-1-7.png\",\"width\":1917,\"height\":1025,\"caption\":\"Figure 1. I2C_EV_IRQHandling() API.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32 I2C Lecture 57: I2C slave support in driver\"}]},{\"@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 57: I2C slave support in driver","description":"I2C slave support in driver. Let\u2019s implement all the callback events for slave transmitter and slave receiver. Go to the event IRQ handling","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-i2c-lecture-57-i2c-slave-support-in-driver\/","og_locale":"en_US","og_type":"article","og_title":"STM32 I2C Lecture 57: I2C slave support in driver","og_description":"I2C slave support in driver. Let\u2019s implement all the callback events for slave transmitter and slave receiver. Go to the event IRQ handling","og_url":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2021-01-23T04:57:06+00:00","article_modified_time":"2022-11-23T05:06:36+00:00","og_image":[{"width":1917,"height":1025,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.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\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"STM32 I2C Lecture 57: I2C slave support in driver","datePublished":"2021-01-23T04:57:06+00:00","dateModified":"2022-11-23T05:06:36+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/"},"wordCount":726,"commentCount":47,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.png","keywords":["STM32 I2C Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/","url":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/","name":"STM32 I2C Lecture 57: I2C slave support in driver","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.png","datePublished":"2021-01-23T04:57:06+00:00","dateModified":"2022-11-23T05:06:36+00:00","description":"I2C slave support in driver. Let\u2019s implement all the callback events for slave transmitter and slave receiver. Go to the event IRQ handling","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2021\/01\/Figure-1-7.png","width":1917,"height":1025,"caption":"Figure 1. I2C_EV_IRQHandling() API."},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/stm32-i2c-lecture-57-i2c-slave-support-in-driver\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"STM32 I2C Lecture 57: I2C slave support in driver"}]},{"@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\/4946","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=4946"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/4946\/revisions"}],"predecessor-version":[{"id":12595,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/4946\/revisions\/12595"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/4948"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=4946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=4946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=4946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}