{"id":2591,"date":"2019-06-04T08:49:45","date_gmt":"2019-06-04T08:49:45","guid":{"rendered":""},"modified":"2019-06-04T16:50:10","modified_gmt":"2019-06-04T08:50:10","slug":"stm32%e5%8d%95%e7%89%87%e6%9c%ba%e4%bd%bf%e7%94%a8%e5%ae%9a%e6%97%b6%e5%99%a8%e4%b8%ad%e6%96%ad%e6%96%b9%e5%bc%8f%e5%ae%9e%e7%8e%b0%e6%af%ab%e7%a7%92%e7%ba%a7%e5%bb%b6%e6%97%b6%e7%9a%84","status":"publish","type":"post","link":"http:\/\/www.szryc.com\/?p=2591","title":{"rendered":"STM32\u5355\u7247\u673a\u4f7f\u7528\u5b9a\u65f6\u5668\u4e2d\u65ad\u65b9\u5f0f\u5b9e\u73b0\u6beb\u79d2\u7ea7\u5ef6\u65f6\u7684"},"content":{"rendered":"

\n\t\u56e0\u4e3aSTM32<\/u> HAL\u5e93\u4e2d\u4ec5\u6709\u5bf9HAl_Delay\uff08\uff09\u6beb\u79d2\u7ea7\u7684\u5ef6\u65f6\uff0c\u4e3a\u5b9e\u73b0\u7cbe\u786e\u7684\u5fae\u79d2\u7ea7\u5ef6\u65f6\uff0c\u5c31\u4e0d\u5f97\u4e0d\u4fee\u6539Systi<\/u>ck\uff0c\u4f46\u7531\u4e8eHAL\u5e93\u5185\u90e8\u4f7f\u7528\u5176\u4f5c\u4e3a\u8d85\u65f6\u5224\u65ad\u7b49\u64cd\u4f5c\uff0c\u5bf9\u5176\u4fee\u6539\u4f1a\u53d1\u751f\u4e0d\u53ef\u9884\u671f\u7684\u9519\u8bef\uff0c\u4e0d\u5efa\u8bae\u4fee\u6539\u3002\u56e0\u6b64\uff0c\u4f7f\u7528\u901a\u7528\u5b9a\u65f6\u5668<\/u>\u8fdb\u884c\u5b9a\u65f6\u64cd\u4f5c\u3002<\/p>\n

\n\t\"STM32\u5355\u7247\u673a\u4f7f\u7528\u5b9a\u65f6\u5668\u4e2d\u65ad\u65b9\u5f0f\u5b9e\u73b0\u6beb\u79d2\u7ea7\u5ef6\u65f6\u7684\u8bbe\u8ba1\"<\/p>\n

\n\t <\/div>\n

\n\t\u53c2\u8003\u7f51\u4e0a\u4f8b\u7a0b\uff0c\u4f7f\u7528\u5b9a\u65f6\u5668\u4e2d\u65ad\u65b9\u5f0f\u5b9e\u73b0\u5ef6\u65f6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

\n\tTIM3\u6ea2\u51fa\u65f6\u95f4=72MHz\/\uff0871+1\uff09\/\uff080+1\uff09=1Mhz=1us<\/p>\n

\n\t\u8ba1\u6570\u6a21\u5f0f\uff1a\u5411\u4e0a\u8ba1\u6570\u6a21\u5f0f<\/p>\n

\n\t\u4f7f\u80fdTIM3\u4e2d\u65ad<\/p>\n

\n\t*\/<\/p>\n

\n\t__IO staTIc uint32_t usDelay=0\uff1b<\/p>\n

\n\tvoid Delayms\uff08uint32_t ms\uff09<\/p>\n

\n\t{<\/p>\n

\n\tDelayus\uff08ms*1000\uff09;<\/p>\n

\n\t}<\/p>\n

\n\tvoid Delayus\uff08uint32_t us\uff09<\/p>\n

\n\t{<\/p>\n

\n\tusDelay=us;<\/p>\n

\n\tHAL_TIM_Base_Start_IT\uff08&htim3\uff09;<\/p>\n

\n\twhile\uff08usDelay\uff09;<\/p>\n

\n\tHAL_TIM_Base_Stop_IT\uff08&htim3\uff09;<\/p>\n

\n\t}<\/p>\n

\n\t\/\/\u91cd\u5199\u56de\u8c03\u51fd\u6570<\/p>\n

\n\tvoid HAL_TIM_PeriodElapsedCallback\uff08TIM_HandleTypeDef *htim\uff09<\/p>\n

\n\t{<\/p>\n

\n\tif\uff08htim-\u300bInstance == TIM3\uff09<\/p>\n

\n\t{<\/p>\n

\n\tif\uff08usDelay\uff01=0\uff09<\/p>\n

\n\t{<\/p>\n

\n\tusDelay--;<\/p>\n

\n\t}<\/p>\n

\n\t}<\/p>\n

\n\t}<\/p>\n

\n\t\u867d\u7136\u8bf4\u4ee5\u4e0a\u7a0b\u5e8f\u7684\u5e76\u6ca1\u4ec0\u4e48\u9519\u8bef\uff0c\u4f46\u5728\u5b9e\u9645\u8fd0\u884c\u4e2d\uff0c\u5374\u65e0\u6cd5\u5f97\u5230\u6b63\u786e\u7684\u8fd0\u884c\u3002\u540c\u65f6\uff0c\u5728\u8fdb\u884cDebug\u8c03\u8bd5\u65f6\uff0c\u5355\u6b65\u6267\u884c\u53c8\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n

\n\t\u4e3b\u8981\u539f\u56e0\u5728\u4e8e\uff1a\u4e2d\u65ad\u95f4\u9694\u65f6\u95f4\u592a\u77ed\uff0c\u5bfc\u81f4\u4e2d\u65ad\u51fd\u6570\u8fd8\u6ca1\u6709\u8fd0\u884c\u5b8c\u6210\uff0c\u5176\u4e2d\u65ad\u6807\u5fd7\u4f4d\u5374\u518d\u6b21\u7f6e\u4f4d\uff0c\u5bfc\u81f4\u5728\u7a0b\u5e8f\u5361\u6b7b\u3002<\/p>\n

\n\t\u56e0\u6b64\uff0c\u5173\u95ed\u5b9a\u65f6\u5668\u4e2d\u65ad\uff0c\u91c7\u7528\u5b9a\u65f6\u5668\u8f6e\u8be2\u7684\u65b9\u5f0f\u5b9e\u73b0\u5ef6\u65f6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

\n\t\/*<\/p>\n

\n\tTIM3\u6ea2\u51fa\u65f6\u95f4=72MHz\/\uff0871+1\uff09\/\uff080+1\uff09=1Mhz=1us<\/p>\n

\n\t\u8ba1\u6570\u6a21\u5f0f\uff1a\u5411\u4e0b\u8ba1\u6570\u6a21\u5f0f<\/p>\n

\n\t*\/<\/p>\n

\n\tvoid Delay_us\uff08uint32_t us\uff09{<\/p>\n

\n\tuint16_t counte<\/u>r=us&0xffff;<\/p>\n

\n\tHAL_TIM_Base_Start\uff08&htim3\uff09;<\/p>\n

\n\t__HAL_TIM_SetCounter\uff08&htim3\uff0ccounter\uff09;<\/p>\n

\n\twhile\uff08counter\u300b1\uff09<\/p>\n

\n\t{<\/p>\n

\n\tcounter=__HAL_TIM_GetCounter\uff08&htim3\uff09;<\/p>\n

\n\t}<\/p>\n

\n\tHAL_TIM_Base_Stop\uff08&htim3\uff09;<\/p>\n

\n\t}<\/p>\n

\n\tvoid Delay_ms\uff08uint32_t ms\uff09{<\/p>\n

\n\tDelay_us\uff081000*ms\uff09;<\/p>\n

\n\t}<\/p>\n","protected":false},"excerpt":{"rendered":"

\u56e0\u4e3a STM32 HAL\u5e93\u4e2d\u4ec5\u6709\u5bf9HAl_Delay\uff08\uff09\u6beb\u79d2\u7ea7\u7684\u5ef6\u65f6\uff0c\u4e3a\u5b9e\u73b0\u7cbe\u786e\u7684\u5fae\u79d2\u7ea7\u5ef6\u65f6\uff0c\u5c31\u4e0d\u5f97\u4e0d\u4fee\u6539Sys ti ck\uff0c\u4f46\u7531\u4e8eHAL\u5e93\u5185\u90e8\u4f7f\u7528\u5176\u4f5c\u4e3a\u8d85\u65f6\u5224\u65ad\u7b49\u64cd\u4f5c\uff0c\u5bf9\u5176\u4fee\u6539\u4f1a\u53d1\u751f\u4e0d\u53ef\u9884\u671f\u7684\u9519\u8bef\uff0c\u4e0d\u5efa<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/2591"}],"collection":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2591"}],"version-history":[{"count":0,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/2591\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2591"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}