{"id":4310,"date":"2024-04-27T12:59:41","date_gmt":"2024-04-27T07:29:41","guid":{"rendered":"https:\/\/cthecosmos.com\/?p=4310"},"modified":"2024-04-27T12:59:41","modified_gmt":"2024-04-27T07:29:41","slug":"%f0%9d%90%81%f0%9d%90%a2%f0%9d%90%ad-%f0%9d%90%81%f0%9d%90%9a%f0%9d%90%a7%f0%9d%90%a0%f0%9d%90%a2%f0%9d%90%a7%f0%9d%90%a0","status":"publish","type":"post","link":"https:\/\/cthecosmos.com\/?p=4310","title":{"rendered":"~~~ \ud835\udc01\ud835\udc22\ud835\udc2d \ud835\udc01\ud835\udc1a\ud835\udc27\ud835\udc20\ud835\udc22\ud835\udc27\ud835\udc20 ~~~"},"content":{"rendered":"\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-0c725b0a3b0fccb4b1035f774df7fa45\" style=\"font-size:17px;line-height:1.8\">Bit banging is a software-based method of interfacing with external devices using standard input\/output operations rather than specialized peripheral interfaces or hardware modules. The term &#8220;bit banging&#8221; comes from the fact that the software is directly &#8220;banging&#8221; (setting or clearing) bits to control an interface.<br><br>Imagine you&#8217;re working on an embedded project using an older or a very basic microcontroller that does not have a built-in hardware SPI module. You need to interface with an SPI-based EEPROM chip to store some configuration data.<br><br>The SPI protocol typically involves the following signals:<br><br>&#8211; \ud835\udc0c\ud835\udc0e\ud835\udc12\ud835\udc08 (Master Out Slave In): Data line for sending data from the master to the slave.<br>&#8211; \ud835\udc0c\ud835\udc08\ud835\udc12\ud835\udc0e (Master In Slave Out): Data line for sending data from the slave to the master.<br>&#8211; \ud835\udc12\ud835\udc02\ud835\udc0a (Serial Clock): Clock signal generated by the master to synchronize data transfer.<br>&#8211; \ud835\udc02\ud835\udc12\/\ud835\udc12\ud835\udc12 (Chip Select\/Slave Select): Signal to activate a particular slave (in this case, the EEPROM).<br><br>To write a byte \ud835\udfce\ud835\udc1b\ud835\udfcf\ud835\udfcf\ud835\udfce\ud835\udfce\ud835\udfcf\ud835\udfce\ud835\udfcf\ud835\udfce to the EEPROM, you&#8217;d need to generate the appropriate signals on these lines in sync with the SPI protocol.<br><br>Without a dedicated SPI hardware module, you&#8217;d use general-purpose I\/O pins on your microcontroller to emulate the SPI signals. Here&#8217;s a simplified step-by-step process for sending the byte 0b11001010:<br><br>1. Set the CS\/SS line low to select the EEPROM.<br>2. For each bit in the byte 0b11001010:<br>&#8211; If the bit is 1, set MOSI high; if it&#8217;s 0, set MOSI low.<br>&#8211; Toggle the SCK line (low to high to low) to indicate to the EEPROM to read the bit on the MOSI line.<br>3. Set the CS\/SS line high to deselect the EEPROM and finish the operation.<br><br>For the byte 0b11001010:<br><br>1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0High\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0High\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Low\u00a0\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Low\u00a0\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0High\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Low\u00a0\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0High\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br>0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Low\u00a0\u00a0\u00a0\u00a0Toggle SCK (L-&gt;H-&gt;L)<br><br>This is just a simplified example.<br><br>This manual control, bit-by-bit, of the interface is what constitutes &#8220;<strong>bit banging<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image alignfull size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"396\" data-attachment-id=\"4312\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=4312\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/pobbitbanging-1.png?fit=1300%2C515&amp;ssl=1\" data-orig-size=\"1300,515\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pobbitbanging-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/pobbitbanging-1.png?fit=1000%2C396&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/pobbitbanging-1.png?resize=1000%2C396&#038;ssl=1\" alt=\"\" class=\"wp-image-4312\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-e9f6e865157006c2f3e3d3a7c0fc3a1d\" style=\"font-size:17px;line-height:1.8\"><strong>How to observe bit-banging in the above?<\/strong><br><br>1. Manually setting the CS\/SS line low using a digital I\/O operation.<br>2. Iterating over each bit of the byte 0b11001010:<br>&#8211; Manually setting the MOSI line state based on each bit (high for &#8216;1&#8217; and low for &#8216;0&#8217;) using a digital I\/O operation.<br>&#8211; Manually toggling the SCK line (low to high to low) using digital I\/O operations.<br>3. Manually setting the CS\/SS line high using a digital I\/O operation.<br><br>Each of these steps involves software directly manipulating or &#8220;banging&#8221; the bits of the I\/O pins to generate the desired signals, rather than relying on a specialized hardware module to do it. This direct control by the software is the essence of bit banging.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-4880268d2fd3fbbd85be8e49e50f57e6\">LinkedIn Post: <a href=\"https:\/\/www.linkedin.com\/posts\/t-yashwanth-naidu_earlycareer-embeddedsystems-learning-activity-7114801565332373505-_Ilq\/?utm_source=share&amp;utm_medium=member_desktop\">https:\/\/www.linkedin.com\/posts\/t-yashwanth-naidu_earlycareer-embeddedsystems-learning-activity-7114801565332373505-_Ilq\/?utm_source=share&amp;utm_medium=member_desktop<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-white-color has-text-color has-background has-link-color has-medium-font-size wp-elements-486e7799b35920eece0029316d5e98bd\" style=\"background:linear-gradient(135deg,rgb(35,23,11) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%)\">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><strong>An Article by: <\/strong>Yashwanth Naidu Tikkisetty<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bit banging is a technique to interface with external devices using standard input\/output operations. It involves manually manipulating I\/O pins to generate signals, such as for SPI communication when hardware modules are not available. This software-based approach provides direct control over the interface, avoiding the need for specialized hardware. [Original content shortened for length]<\/p>\n<a href=\"https:\/\/cthecosmos.com\/?p=4310\" class=\"more-link\">Read More <span class=\"screen-reader-text\">~~~ \ud835\udc01\ud835\udc22\ud835\udc2d \ud835\udc01\ud835\udc1a\ud835\udc27\ud835\udc20\ud835\udc22\ud835\udc27\ud835\udc20 ~~~<\/span><\/a>","protected":false},"author":120055267,"featured_media":4311,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[769112296,36985,28627,30181,5495,952411],"tags":[20862692,4998580,772321195,1214,772321193,1354040,402202],"class_list":{"0":"post-4310","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-c-concepts-hub","8":"category-c-programming","9":"category-embedded","10":"category-embedded-systems","11":"category-operating-system","12":"category-short-articles","13":"tag-bit-banging","14":"tag-bit-wise","15":"tag-c-programming","16":"tag-communication","17":"tag-embedded-systems","18":"tag-short-article","19":"tag-spi","21":"fallback-thumbnail"},"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/pobbitbanging.png?fit=1300%2C515&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8CiEf-17w","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/users\/120055267"}],"replies":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4310"}],"version-history":[{"count":6,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4310\/revisions"}],"predecessor-version":[{"id":4318,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4310\/revisions\/4318"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/media\/4311"}],"wp:attachment":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}