{"id":83,"date":"2020-09-04T02:15:24","date_gmt":"2020-09-04T02:15:24","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=83"},"modified":"2020-09-04T02:15:24","modified_gmt":"2020-09-04T02:15:24","slug":"understanding-gpios","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=83","title":{"rendered":"Understanding GPIOs"},"content":{"rendered":"\n<p>As you may know memory holds code and data for the CPU to process ,and \u00a0the I\/ O ports are used by the CPU to access input and output devices.<\/p>\n\n\n\n<p>In the microcontroller we have two types of I\/ O. They are: a. General Purpose I\/ O (GPIO): The GPIO ports are used for interfacing devices such as LEDs, switches, LCD, keypad, and so on. b. Special purpose I\/ O: These I\/ O ports have designated function such as ADC (Analog-to-Digital), Timer, UART (universal asynchronous receiver transmitter), and so on.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide16-1024x576.png\" alt=\"\" width=\"831\" height=\"467\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide17-1-1024x576.png\" alt=\"\" width=\"864\" height=\"485\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Buses<\/h2>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide18-1-1024x576.png\" alt=\"\" width=\"822\" height=\"462\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Direction and Data registers<\/h2>\n\n\n\n<p>Every microcontroller has a minimum of two registers for io control. The keyword here is minimum. We we go to program our mcu we need setup at least 3 or 4 registers depending on the mcu we are using. The to minimum required registers are the data register and the direction register. The Direction register is used to make the pin either input or output.<\/p>\n\n\n\n<p>After the Direction register is properly set up, then we use the Data register to actually write to the pin or read data from the pin.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide19-1-1024x576.png\" alt=\"\" width=\"821\" height=\"461\"\/><\/figure>\n\n\n\n<p><strong>STM32F411-NUCLEO LED BLINK<\/strong><\/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;darcula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&lt;br&gt;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stm32f4xx.h&quot;\n\nvoid delayMs(int n);\n\nint main(void) {\n    RCC-&gt;AHB1ENR |=  1;             \/* enable GPIOA clock *\/\n    \n    GPIOA-&gt;MODER &amp;= ~0x00000C00;   \n    GPIOA-&gt;MODER |=  0x00000400;   \n\n    while(1) {\n        GPIOA-&gt;ODR |=  0x00000020; \n        delayMs(500);\n        GPIOA-&gt;ODR &amp;= ~0x00000020; \n        delayMs(500);\n    }\n}\n\n\/* Psuedo delay based on Keil uVision compiler and  16 MHz SYSCLK *\/\nvoid delayMs(int n) {\n    int i;\n    for (; n &gt; 0; n--)\n        for (i = 0; i &lt; 3195; i++) ;\n}<\/pre><\/div>\n\n\n\n<p><strong>STM32F411-NUCLEO\u00a0<\/strong>INPUT\/OUTPUT<\/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;darcula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&lt;br&gt;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stm32f4xx.h&quot;\n\nint main(void) {\n    RCC-&gt;AHB1ENR |=  4;                 \n    RCC-&gt;AHB1ENR |=  1;                \n\n    GPIOA-&gt;MODER &amp;= ~0x00000C00;        \n    GPIOA-&gt;MODER |=  0x00000400;        \n\n    GPIOC-&gt;MODER &amp;= ~0x0C000000;       \n\n    while(1) {\n        if (GPIOC-&gt;IDR &amp; 0x2000)        \/* if PC13 is high *\/\n            GPIOA-&gt;BSRR = 0x00200000;   \/* turn off green LED *\/\n        else\n            GPIOA-&gt;BSRR = 0x00000020;   \/* turn on green LED *\/\n    }\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As you may know memory holds code and data for the CPU to process ,and \u00a0the I\/ O ports are used by the CPU to access input and output devices. In the microcontroller we have two types of I\/ O. They are: a. General Purpose I\/ O (GPIO): The GPIO ports are used for interfacing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,12],"tags":[10,13],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-peripheral-drivers","category-stm32","tag-peripheral-drivers","tag-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/83"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":84,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions\/84"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}