{"id":77,"date":"2020-09-04T01:55:33","date_gmt":"2020-09-04T01:55:33","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=77"},"modified":"2021-07-14T00:40:46","modified_gmt":"2021-07-14T00:40:46","slug":"understanding-general-purpose-timers","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=77","title":{"rendered":"Understanding General Purpose Timers"},"content":{"rendered":"\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide28-1024x576.png\" alt=\"\" width=\"715\" height=\"401\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide29-1-1024x576.png\" alt=\"\" width=\"800\" height=\"450\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide34-1024x576.png\" alt=\"\" width=\"839\" height=\"471\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide35-1-1024x576.png\" alt=\"\" width=\"799\" height=\"449\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bohobiom.com\/wp-content\/uploads\/2020\/01\/Slide36-1-1024x576.png\" alt=\"\" width=\"908\" height=\"510\"\/><\/figure>\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    \/\/ configure PA5 as output to drive the LED\n    RCC-&gt;AHB1ENR |=  1;             \n    GPIOA-&gt;MODER &amp;= ~0x00000C00;    \n    GPIOA-&gt;MODER |=  0x00000400;    \n    \n    \/\/ configure TIM2 to wrap around at 1 Hz\n    RCC-&gt;APB1ENR |= 1;              \/* enable TIM2 clock *\/\n    TIM2-&gt;PSC = 1600 - 1;           \/* divided by 1600 *\/\n    TIM2-&gt;ARR = 10000 - 1;          \/* divided by 10000 *\/\n    TIM2-&gt;CNT = 0;                  \/* clear timer counter *\/\n    TIM2-&gt;CR1 = 1;                  \/* enable TIM2 *\/\n\n    while (1) {\n        while(!(TIM2-&gt;SR &amp; 1)) {}   \/* wait until UIF set *\/\n        TIM2-&gt;SR &amp;= ~1;             \/* clear UIF *\/\n        GPIOA-&gt;ODR ^= 0x00000020;   \/* toggle green LED *\/\n    }\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","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-77","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\/77"}],"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=77"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/78"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}