{"id":2422,"date":"2024-03-28T13:58:30","date_gmt":"2024-03-28T13:58:30","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2422"},"modified":"2024-03-28T13:58:31","modified_gmt":"2024-03-28T13:58:31","slug":"getting-started-with-stm32wb55-gpio-input","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2422","title":{"rendered":"Getting Started with STM32WB55:  GPIO Input"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1015\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-1024x1015.png\" alt=\"\" class=\"wp-image-2423\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-1024x1015.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-300x297.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-150x150.png 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-768x761.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-750x743.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-400x396.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1-250x248.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-22-at-7.07.10\u202fAM-1.png 1130w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=2403\" target=\"_blank\">here<\/a>), we took a look at how to configure the pin as output. In this guide, we shall configure pins as input and control the state of the 3 on board LEDs.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Input mode.<\/li><li>Driver development.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Input Modes:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>GPIO input modes include<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>high impedance<\/li><li>pull-up<\/li><li>pull-down<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"floating-high-impedance-tri-stated\">Floating, High Impedance, Tri-Stated<\/h4>\n\n\n\n<p>Floating, high impedance, and tri-stated are three terms that mean the same thing: the pin is just flopping in the breeze. Its state is indeterminate unless it is driven high or low externally. You only want to configure a pin as floating if you know it will be driven externally. Otherwise, configure the input using pulling resistors.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"pull-updown\">Pull Up\/Down<\/h4>\n\n\n\n<p>If an input is configured with an internal pull-up, it will be high unless it is externally driven low. Pull-down inputs do the opposite (&nbsp;they\u2019re low unless driven high).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-1024x768.png\" alt=\"\" class=\"wp-image-866\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-1024x768.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-300x225.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-768x576.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-1536x1152.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-1150x862.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-750x562.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-400x300.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM-250x187.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-01-at-5.52.38-PM.png 1566w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Driver Development:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Start off by creating new project and name it GPIO_Input.<\/p>\n\n\n\n<p>After the creating the project.<\/p>\n\n\n\n<p>Configure the LEDs pins and clocks as shown <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=2403\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2403\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>From the STM32WB55 schematic, we can find that the Nucleo has 3 user pish-buttons as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"679\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-1024x679.png\" alt=\"\" class=\"wp-image-2424\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-1024x679.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-300x199.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-768x509.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-1536x1019.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-1150x763.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-750x498.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-400x265.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM-250x166.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/Screenshot-2024-03-28-at-4.46.27\u202fPM.png 2020w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>SW1 is connected to PC4, SW2 to PD0 and SW3 to PD1.<\/p>\n\n\n\n<p>Configure the pins as input as shown here:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-1024x572.jpg\" alt=\"\" class=\"wp-image-2425\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-1024x572.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-300x167.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-768x429.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-1536x857.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-2048x1143.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-1150x642.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-750x419.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-400x223.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-49-56-250x141.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>From System Core, select GPIO and enable the pullup for each input pins.<\/p>\n\n\n\n<p>This is necessary since the buttons don&#8217;t have external pullup resistors.<\/p>\n\n\n\n<p>Now, save the project and this shall generate the required code and open main.c.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In user begin 3 within the while 1 loop:<\/p>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4)==GPIO_PIN_RESET)\n\t  {\n\t\t  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);\n\t  }\n\t  else\n\t  {\n\t\t  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);\n\t  }\n\n\n\t  if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_0)==GPIO_PIN_RESET)\n\t  {\n\t\t  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);\n\t  }\n\t  else\n\t  {\n\t\t  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);\n\t  }\n\n\n\t  if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_1)==GPIO_PIN_RESET)\n\t  {\n\t\t  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);\n\t  }\n\t  else\n\t  {\n\t\t  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);\n\t  }<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"616\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-1024x616.jpg\" alt=\"\" class=\"wp-image-2426\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-1024x616.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-300x180.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-768x462.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-1536x924.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-2048x1231.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-1150x691.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-750x451.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-400x241.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/2024-03-28_16-54-14-250x150.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Save the project and run it on your Nucleo.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"GPIO Input mode on STM32WB55\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/KLkaXIxJnAU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look at how to configure the pin as output. In this guide, we shall configure pins as input and control the state of the 3 on board LEDs. In this guide, we shall cover the following: Input mode. Driver development. Results. 1. Input Modes: GPIO input modes [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12,1],"tags":[],"class_list":["post-2422","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2422"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2422"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2422\/revisions"}],"predecessor-version":[{"id":2427,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2422\/revisions\/2427"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}