{"id":2903,"date":"2024-09-13T11:27:45","date_gmt":"2024-09-13T11:27:45","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=2903"},"modified":"2024-09-13T12:07:35","modified_gmt":"2024-09-13T12:07:35","slug":"capacitive-touch-switch-with-stm8","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=2903","title":{"rendered":"Capacitive Touch switch with STM8"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-89d790dba8ddf840d320b2e428427374 wp-block-paragraph\" style=\"color:#5c5c5c\">The STM8S access line 8-bit microcontrollers offer 8 Kbytes Flash program memory, plus integrated true data EEPROM. It is a low cost device and very powerful. It has internal 16 MHz CPU clock frequency, robust I\/O, independent watchdogs with separate clock source, clock security system, SPI, UART, I<sup>2<\/sup>C etc. It has a single wire (SWIM) interface module and debug module permits non-intrusive, real-time in-circuit debugging and fast memory programming. It will be very useful in small projects, but in this article will only discuss about only GPIO. One GPIO pin will be input and another GPIO pin will be output. The input signal will be given by a capacitive touch switch. Capacitive touch switch has only 3 pins V<sub>cc<\/sub> (ranges from 2.5 to 5.5V), Ground and one I\/O pin which return the logical value. If finger touch the I\/O output will be 1 otherwise 0.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"379\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8-Development-board-1024x379.jpg\" alt=\"\" class=\"wp-image-2906\" style=\"width:767px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8-Development-board-1024x379.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8-Development-board-300x111.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8-Development-board-768x284.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8-Development-board-1536x568.jpg 1536w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8-Development-board.jpg 1549w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-9e8b7d35628fc82a8acb435dbc387e85 wp-block-paragraph\" style=\"color:#5c5c5c\">For developing purpose we need an IDE, Compiler &amp; Burner. &nbsp;Download the following software-<\/p>\n\n\n\n<ul style=\"color:#252525\" class=\"wp-block-list has-text-color has-link-color wp-elements-288b3523374786c76dfec52a8d415440\">\n<li><a href=\"https:\/\/www.st.com\/en\/development-tools\/stvp-stm8.html\" target=\"_blank\" rel=\"noreferrer noopener\">ST Visual Programmer STM8<\/a>(It include ST Visual Develop &amp; ST Visual Programmer)<\/li>\n\n\n\n<li><a href=\"https:\/\/www.cosmicsoftware.com\/download_stm8_free.php\" target=\"_blank\" rel=\"noreferrer noopener\">COSMIC STM8 compiler.<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-2532d81bb0956dc5b5ec91763ee0df00 wp-block-paragraph\" style=\"color:#5c5c5c\">ST Visual Programmer STM8 package include an IDE : ST Visual Develop &amp; burner : ST Visual Programmer. The COSMIC STM8 compiler package doesn\u2019t include license.lic file. When you install the COSMIC software they will provide license.lic file within a few hours via mail. If they don\u2019t mail you after a couple of hours then you have to mail at <a href=\"mailto:stm8_free@cosmic.fr\">stm8_free@cosmic.fr<\/a> with your Machine ID information.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-6fec2aa4309bacaa56a5faf2673a0aa9 wp-block-paragraph\" style=\"color:#5c5c5c\">For your simplicity I just attached the mail body file. When the compiler ask for your license.lic file just browse it. Or just copy your license file to &#8211; C:\\Program Files (x86)\\COSMIC\\FSE_Compilers\\CXSTM8\\License.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"870\" height=\"425\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/function-9.jpg\" alt=\"\" class=\"wp-image-2915\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/function-9.jpg 870w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/function-9-300x147.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/function-9-768x375.jpg 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-14840785ce543d8c3331d7b8c572d456 wp-block-paragraph\" style=\"color:#5c5c5c\">Like STM32 mcu the STM8 has libraries. Download the driver library, it include all peripherals library function i.e. GPIO, I<sup>2<\/sup>C, SPI, UART etc. <\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-left is-layout-flex wp-container-core-buttons-is-layout-b192c3d7 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8S-Driver-File.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--50)\">Download The STM8s103 Library<\/a><\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-0671ec61df7705b9e2b8b0e15b1d1248 wp-block-paragraph\" style=\"color:#5c5c5c\">Here we will discuss about the GPIO library, which include stm8s_gpio.c &amp; stm8s_gpio.h file. Some user functions as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n\/\/Initializes the GPIOx according to the specified parameters\nGPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode);\n\/\/Writes data to the specified GPIO data port\nGPIO_Write(GPIO_TypeDef* GPIOx, uint8_t PortVal);   \n\/\/Writes high level to the specified GPIO pins\nGPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);\n\/\/Writes low level to the specified GPIO pins\nGPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);\n\/\/Writes reverse level to the specified GPIO pins\nGPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);\n\/\/Reads the specified GPIO output data port\nGPIO_ReadOutputData(GPIO_TypeDef* GPIOx);\n\/\/Reads the specified GPIO input data port\nGPIO_ReadInputData(GPIO_TypeDef* GPIOx);\n\/\/Reads the specified GPIO input data pin\nGPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);\n\/\/Configures the external pull-up on GPIOx pins\nGPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-4cd78e3b31b66982ad5bdb89d9cbff2d wp-block-paragraph\" style=\"color:#5c5c5c\">Our target is to read one GPIO pin with no pull-up enable and set\/reset one GPIO output pin according to the input pin.<\/p>\n\n\n\n<ul style=\"color:#252525\" class=\"wp-block-list has-text-color has-link-color wp-elements-92fe84d3f146845834d8d8ac90685e2c\">\n<li>GPIO PB4 as input (connect capacitive touch I\/O pin)<\/li>\n\n\n\n<li>GPIO PD5 as output<\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-e895d3b5454daebee241341b688e35f0 wp-block-paragraph\" style=\"color:#5c5c5c\">First we have to initial GPIO according to logic-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nGPIO_Init(GPIOB,GPIO_PIN_4,GPIO_MODE_IN_FL_NO_IT);    \/\/PB4 as input\nGPIO_Init(GPIOD,GPIO_PIN_5,GPIO_MODE_OUT_PP_LOW_FAST);\/\/PD5 as output\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-124080f6cddc2658736d908b627c0812 wp-block-paragraph\" style=\"color:#5c5c5c\">Initialization has been done. The full program as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n#include &quot;stm8s_gpio.h&quot;\nmain()\n{\n\tGPIO_Init(GPIOD,GPIO_PIN_5,GPIO_MODE_OUT_PP_LOW_FAST);\n\tGPIO_Init(GPIOB,GPIO_PIN_4,GPIO_MODE_IN_FL_NO_IT);\n\twhile (1)\n            {\n              if(GPIO_ReadInputPin(GPIOB,GPIO_PIN_4))\n              GPIO_WriteHigh(GPIOD,GPIO_PIN_5);\n              else GPIO_WriteLow(GPIOD,GPIO_PIN_5);\n            }\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-2810c64824776bb0143c26a3592a82f1 wp-block-paragraph\" style=\"color:#5c5c5c\">Our programming part is done. It will generate .s19 file, the next step is to load the file in STM8. Here we use STM8S103F3P6 low cost mcu, first change the setting of ST Visual Programmer-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nHardware         : ST-LINK\nPORT             : USB\nProgramming mode : SWIM\nDevice           : STM8S103F3\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-56dc766e5a825767df49c82826d4cb89 wp-block-paragraph\" style=\"color:#5c5c5c\">Only 1 pin will be require for programming, that is SWIM. Connect USB power supply to the module and SWIM pin to ST-Link SWIM pin. If you are using external power supply to power the module then connect GND pin of ST-Link to the GND pin.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"415\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8S-interface-1024x415.jpg\" alt=\"\" class=\"wp-image-2929\" style=\"width:776px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8S-interface-1024x415.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8S-interface-300x121.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8S-interface-768x311.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/STM8S-interface.jpg 1361w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\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 title=\"STM8S GPIO\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/rmmdib_p6WU?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 class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/GPIO.rar\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-5bb8cb307ee4462a29d1a3233e53ec4f wp-block-paragraph\" style=\"color:#252525\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/GPIO.rar\">GPIO.rar<\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The STM8S access line 8-bit microcontrollers offer 8 Kbytes Flash program memory, plus integrated true data EEPROM. It is a low cost device and very powerful. It has internal 16 MHz CPU clock frequency, robust I\/O, independent watchdogs with separate clock source, clock security system, SPI, UART, I2C etc. It has a single wire (SWIM) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-2903","post","type-post","status-publish","format-standard","hentry","category-arm-standards-peripherals"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2903"}],"version-history":[{"count":23,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2903\/revisions"}],"predecessor-version":[{"id":2945,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2903\/revisions\/2945"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}