{"id":479,"date":"2017-11-24T23:53:05","date_gmt":"2017-11-24T22:53:05","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=479"},"modified":"2017-12-30T19:39:05","modified_gmt":"2017-12-30T18:39:05","slug":"72-hc_sr04-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f4\/komplette-library-liste-stm32f4\/72-hc_sr04-library-stm32f4\/","title":{"rendered":"72-HC_SR04-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f4\/komplette-library-liste-stm32f4\/71-am2301-library-stm32f4\/\" title=\"71-AM2301-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 71-AM2301-Library (STM32F4)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f4\/komplette-library-liste-stm32f4\/73-freertos-library-stm32f4\/\" title=\"73-FreeRTOS-Library (STM32F4)\">73-FreeRTOS-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit dieser Library kann der Ultraschall-Abstands-Sensor vom Typ (HC-SR04) an die STM32F4-CPU angeschlossen werden.<\/p>\n<p>Wieder ein DANKE an \u201c<strong>Joerg<\/strong>\u201d f\u00fcr den Sensor<\/p>\n<p>Das Modul wird an 5V angeschlossen und mit einem 10 us langen Hi-Impuls \u00fcber den Pin \u201cTrigger\u201d zu einer Abstandsmessung veranlasst.<\/p>\n<p>Die L\u00e4nge vom Hi-Pegel am \u201cEcho-Pin\u201d die das Modul daraufhin zur\u00fcckliefert ist ein Ma\u00df f\u00fcr den ermittelten Abstand.<\/p>\n<p>Der Sensor soll laut Datenblatt Abst\u00e4nde von 2 cm bis 400 cm mit einer Aufl\u00f6sung von 3 mm Messen k\u00f6nnen. Ich habe hier etwa 5 cm bis 130 cm messen k\u00f6nnen, das h\u00e4ngt wohl sehr viel von der Umgebung ab.<\/p>\n<p>Ein Hinweis zur Benutzung der Library : Der gemessene Abstandswert wird als \u201cfloat\u201d in \u201ccm\u201d zur\u00fcckgeliefert und bei einem Timeout (z.B. wenn kein Sensor angeschlossen ist oder wenn der Abstand &gt; 5m) , wird eine -1 als Fehlererkennung zur\u00fcckgeliefert)<\/p>\n<p>Nach der Messung macht die Funktion ein Delay von 60ms (der Wert steht im H-File) weil laut Datenblatt der Sensor nicht schneller abgefragt werden soll.<br \/>\n(falls ihr in eurem Programm sicherstellt das eh nicht schneller gepollt wird, k\u00f6nnt ihr das l\u00f6schen)<\/p>\n<p>Hinweis zur Pinbelegung : Der Trigger-Pin kann im H-File beliebig gew\u00e4hlt werden, aber der Echo-Pin muss zum benutzten Timer passen (weil der im Input-Capture-Mode betrieben wird)<\/p>\n<p><strong>Bilder :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/12\/hcsr04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3276\" src=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/12\/hcsr04-300x179.jpg\" alt=\"hcsr04\" width=\"300\" height=\"179\" \/><\/a><\/p>\n<p><strong>Pinbelegung :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">PA0 = Echo-Pin\r\nPD3 = Trigger-Pin<\/pre>\n<p><strong>Voraussetzungen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : GPIO, TIM, MISC\r\nBenutzte Librarys : keine<\/pre>\n<p><strong>Funktionen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">void UB_HCSR04_Init(void);          \/\/ init vom Sensor\r\nfloat UB_HCSR04_Distance_cm(void);  \/\/ Abstandsmessung (in cm)<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 22.12.2013\r\n\/\/ Version  : 1.0\r\n\/\/ Autor    : UB\r\n\/\/ EMail    : mc-4u(@)t-online.de\r\n\/\/ Web      : www.mikrocontroller-4u.de\r\n\/\/ CPU      : STM32F4\r\n\/\/ IDE      : CooCox CoIDE 1.7.4\r\n\/\/ GCC      : 4.7 2012q4\r\n\/\/ Module   : CMSIS_BOOT, M4_CMSIS_CORE\r\n\/\/ Funktion : Demo der HC-SR04-Library\r\n\/\/ Hinweis  : Diese zwei Files muessen auf 8MHz stehen\r\n\/\/              \"cmsis_boot\/stm32f4xx.h\"\r\n\/\/              \"cmsis_boot\/system_stm32f4xx.c\"\r\n\/\/--------------------------------------------------------------\r\n\r\n#include \"main.h\"\r\n#include \"stm32_ub_led.h\"\r\n#include \"stm32_ub_hcsr04.h\"\r\n\r\nint main(void)\r\n{\r\n  float abstand;\r\n\r\n  SystemInit(); \/\/ Quarz Einstellungen aktivieren\r\n\r\n  \/\/ init der LEDs\r\n  UB_Led_Init();\r\n\r\n  \/\/ init vom HC-SR04\r\n  UB_HCSR04_Init();\r\n\r\n  while(1)\r\n  {\r\n    \/\/ Messung vom Abstand\r\n    abstand=UB_HCSR04_Distance_cm();\r\n    if(abstand&gt;0) {\r\n      \/\/ LEDs je nach Entfernung schalten\r\n      UB_Led_Off(LED_RED);\r\n      UB_Led_On(LED_ORANGE);\r\n      if(abstand&lt;10.0) UB_Led_On(LED_GREEN); else UB_Led_Off(LED_GREEN);\r\n      if(abstand&lt;15.0) UB_Led_On(LED_BLUE); else UB_Led_Off(LED_BLUE);\r\n    }\r\n    else {\r\n      \/\/ au\u00dferhalb vom Messbereich\r\n      UB_Led_On(LED_RED);\r\n      UB_Led_Off(LED_GREEN);\r\n      UB_Led_Off(LED_BLUE );\r\n      UB_Led_Off(LED_ORANGE);\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>Hier die Library zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/12\/ub_stm32f4_hcsr04_v100.zip\">ub_stm32f4_hcsr04_v100<\/a><\/p>\n<p>Hier der komplette CooCox-Projektordner zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/12\/Demo_72_HCSR04.zip\">Demo_72_HCSR04<\/a><\/p>\n<hr \/>\n<h3 id=\"comments-title\">12 Antworten auf <em>72-HC_SR04-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-1198\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-1198\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/b894d67379dd0647dd316009f47155d2?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Joerg<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">22. Dezember 2013 um 22:59<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>ich hat die Dinger schon ein paar Jahre liegen, vielleicht durch Alterung die nur noch geringe Reichweite. Am Atmega damals war gr\u00f6\u00dferer Abstand m\u00f6glich soweit ich mich erinnere.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-1463\" class=\"comment odd alt thread-odd thread-alt depth-1\">\n<div id=\"comment-1463\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/4a9d85baedb3609a9e6a8fec48297684?s=40&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Christoph<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">12. M\u00e4rz 2014 um 12:12<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>hi!<\/p>\n<p>zun\u00e4chst mal Gl\u00fcckwunsch und Dank f\u00fcr deine Arbeit. Da hast du schon eine Menge auf die Beine gestellt.<\/p>\n<p>Ich habe aber auch eine Frage bzw. ein Problem mit dem Code. Eigentlich ist es vielleicht eher ein Verst\u00e4ndnisproblem bei der Timer Initialisierung:<br \/>\nDu bildest du Differenz von 2 Capture Zeiten.<br \/>\nstart=TIM_GetCapture1(TIM2);<br \/>\nstop=TIM_GetCapture2(TIM2);<br \/>\nHCSR04.delay_us=start-stop;<br \/>\nAber woher kommen denn 2 Zeiten der Trigger ist doch nur der Receive Pin, also Input 1. Verstehe nicht wie das gedacht ist und funktioniert.<\/p>\n<p>Kurzes Feedback mit Erkl\u00e4rung w\u00e4re genial!<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-1464\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-1464\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/4a9d85baedb3609a9e6a8fec48297684?s=40&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Christoph<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">12. M\u00e4rz 2014 um 12:34<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Schande \u00fcber mich \u2013 kurz nach Hilferuf erkenne ich, dass der periph. driver offenbar eine spezielle Funktion TIM_PWMIConfig() hat. Der wird dann wohl die beiden channels scharf schalten.<br \/>\nSorry, habe ich fast 4 Stunden nicht geblickt. Man sieht aber auch den Nachteil eines Treiberpaketes gegen\u00fcber einzelnem Bitsetzen ist. Man muss die Funktionen kennen da hilft das Datenblatt nicht <img decoding=\"async\" class=\"wp-smiley\" src=\"wp-includes\/images\/smilies\/icon_wink.gif\" alt=\";-)\" \/><\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-2032\" class=\"comment odd alt thread-odd thread-alt depth-1\">\n<div id=\"comment-2032\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/5dec7d06ec488d7871c5b38fa9a242dd?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\"><a class=\"url\" href=\"http:\/\/na\/\" rel=\"external nofollow\">Maurice<\/a><\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">15. August 2014 um 03:28<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>All I can say is thank you so much for posting this! It has helped me a lot!!!<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-3154\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-3154\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/d9ac7798bbd420a79cc31fd81e10f0e0?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Niels<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">23. April 2015 um 11:10<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hi,<\/p>\n<p>This code works realy well. I\u2019m trying to get more ultrasones to work, one after the other. I can\u2019t get it to work. Can you give me some tips for it?<\/p>\n<p>Tanks.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-3156\" class=\"comment byuser comment-author-admin_ub bypostauthor odd alt depth-2\">\n<div id=\"comment-3156\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/67426419ead44d5afa132e92685bb460?s=40&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">admin_ub<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">23. April 2015 um 21:21<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>easy\u2026change the function \u201cP_HCSR04_Trigger\u201d<br \/>\nso you can set multiple trigger outputs<br \/>\nand connect all echo pins with a wired or (some bat46 diodes and a single pull up resistor)<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-3823\" class=\"comment even thread-odd thread-alt depth-1\">\n<div id=\"comment-3823\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/3caacd89408b9aad4f7db8e2524e8456?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">alex<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">14. Juli 2015 um 21:31<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>hello,<\/p>\n<p>code ist echt hilfreich und verst\u00e4ndlich.<br \/>\nich wollte die abstandsmessung periodisch mit einem zus\u00e4tzlichen timer5 ansto\u00dfen.<\/p>\n<p>leider bleibt der code h\u00e4ngen.<br \/>\nhabe nur die Timer init in die main eingebaut und die timer5 isr<\/p>\n<p>TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure2;<br \/>\nNVIC_InitTypeDef NVIC_InitStructure2;<\/p>\n<p>NVIC_InitStructure2.NVIC_IRQChannel = TIM5_IRQn;<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE;<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 0x0A;<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelSubPriority = 0x0A;<br \/>\nNVIC_Init(&amp;NVIC_InitStructure2);<\/p>\n<p>RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);<\/p>\n<p>TIM_TimeBase_InitStructure2.TIM_ClockDivision = TIM_CKD_DIV1;<br \/>\nTIM_TimeBase_InitStructure2.TIM_CounterMode = TIM_CounterMode_Up;<br \/>\nTIM_TimeBase_InitStructure2.TIM_Period = 1999;<br \/>\nTIM_TimeBase_InitStructure2.TIM_Prescaler = 17999;<br \/>\nTIM_TimeBaseInit(TIM5, &amp;TIM_TimeBase_InitStructure2);<\/p>\n<p>TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);<br \/>\nTIM_Cmd(TIM5, ENABLE);<\/p>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013<\/p>\n<p>void TIM5_IRQHandler(void) {<\/p>\n<p>float abstand = 0;<br \/>\nchar text[10];<\/p>\n<p>TIM_ClearITPendingBit(TIM5, TIM_IT_Update);<br \/>\nGPIOG-&gt;ODR ^= GPIO_Pin_13; \/\/ PG13 toggeln<\/p>\n<p>itoa(zahl, text, 10);<\/p>\n<p>abstand = UB_HCSR04_Distance_cm();<br \/>\nitoa(abstand, text, 10);<\/p>\n<p>if (abstand &gt; 0) {<br \/>\n\/\/ LEDs je nach Entfernung schalten<br \/>\nUB_Font_DrawString(10, 160, text, &amp;Arial_14x22, RGB_COL_BLACK,<br \/>\nRGB_COL_WHITE);<\/p>\n<p>} else {<br \/>\n\/\/ au\u00dferhalb vom Messbereich<br \/>\nitoa(zahl, text, 10);<br \/>\nUB_Font_DrawString(10, 130, text, &amp;Arial_14x22, RGB_COL_BLACK,<br \/>\nRGB_COL_WHITE);<br \/>\n}<br \/>\nzahl++;<br \/>\n}<br \/>\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\nwenn ich \u201cabstand = UB_HCSR04_Distance_cm();\u201d auskommentiere dann funktioniert die ISR und die zahl wird auf dem Display hochgez\u00e4hlt. ganz strange.<br \/>\nwenn ich \u201cabstand = UB_HCSR04_Distance_cm();\u201d wieder einkommentiere dann h\u00f6re ich den US-Sensor direkt summen. aber das programm h\u00e4ngt.<br \/>\nlese ich \u201cabstand = UB_HCSR04_Distance_cm();\u201d in der main while aus dann funktioniert alles.<\/p>\n<p>hat wer eine idee woran es liegen kann?<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-3829\" class=\"comment odd alt thread-even depth-1\">\n<div id=\"comment-3829\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/d76f7a3ade81cb8ceef101af99c148b3?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Lucas<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">15. Juli 2015 um 14:33<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>mach mal statt:<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 0x0A;<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelSubPriority = 0x0A;<\/p>\n<p>das hier:<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 0\u00d701;<br \/>\nNVIC_InitStructure2.NVIC_IRQChannelSubPriority = 0\u00d700;<\/p>\n<p>die 0x0A gehen nicht bei beiden Prioritys (sieh dir dazu mal die datei \u201cmisc.c\u201d aus der StdPeriphLib an) Es gibt spezielle einstellungen da gehts bis 0x0E aber nicht bei beiden gleichzeitig (siehe Funktion in misc.c: void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup))! Wahrscheinlich wird dein Priority (0x0A) durch 0\u00d700 ersetzt und blockiert damit die TIM_IRQ, in der die Messung stattfindet!<\/p>\n<p>Lg Lue<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-3834\" class=\"comment even depth-2\">\n<div id=\"comment-3834\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/3caacd89408b9aad4f7db8e2524e8456?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">alex<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">15. Juli 2015 um 18:31<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>danke f\u00fcr die antwort.<br \/>\nhabe die priorit\u00e4ten ge\u00e4ndert aber es hat sich nix ge\u00e4ndert.<br \/>\ndas programm bleibt einfach h\u00e4ngen \u2013 nichtmal die isr werden angesprungen.<br \/>\nwenn ich den abstand in der main while permanent abfrage dann funktioniert auch die timer5_isr ohne probleme.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-3844\" class=\"comment odd alt depth-3\">\n<div id=\"comment-3844\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/d76f7a3ade81cb8ceef101af99c148b3?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Lucas<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">15. Juli 2015 um 21:07<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>M\u00d6GLICHKEIT 1:<br \/>\nDann versuch mal in der main-Schleife direkt nach \u201cSystemInit();\u201d das hier einzuf\u00fcgen:<\/p>\n<p>NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);<\/p>\n<p>damit kannst du<br \/>\n0-7 f\u00fcr Preemption Priority und<br \/>\n0-1 f\u00fcr Subpriorit<br \/>\nausw\u00e4hlen. (Falls du aus bestimmten gr\u00fcnden mehr Subprioritys brauchst siehe \u201cmisc.c\u201d daf\u00fcr gibts dann ander NVIC_PriorityGroup_X konfigurationen.)<\/p>\n<p>Du ben\u00f6tigst auf jeden Fall ein h\u00f6here PreemptionPriority als TIM2&amp;7 von der Distanzmessung also mindestens 0\u00d701!<\/p>\n<p>M\u00d6GLICHKEIT 2:<br \/>\nMach mal die Initialisierung von deinem TIMER5 bevor du die NVIC_Init von TIM5_IRQ machst!<\/p>\n<p>M\u00d6GLICHKEIT 3:<br \/>\nNoch ein Tipp, sicherheitshalber so \u2013&gt;<\/p>\n<p>void TIM5_IRQHandler(void)<br \/>\n{<br \/>\nif (TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET) {<br \/>\nTIM_ClearITPendingBit(TIM5, TIM_IT_Update);<br \/>\n\/\/<br \/>\n\/\/Dein Code<br \/>\n}<br \/>\n}<\/p>\n<p>Sonst hab ich momentan auch keinen Plan!<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-3848\" class=\"comment even depth-4\">\n<div id=\"comment-3848\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/d76f7a3ade81cb8ceef101af99c148b3?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Lucas<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">15. Juli 2015 um 21:45<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>PS: Mit \u201ch\u00f6here PreemptionPriority als TIM2&amp;7\u2033 meinte ich nat\u00fcrlich, dass die Zahl h\u00f6her sein muss, das bedeutet nat\u00fcrlich dann eine niedrigere Priorit\u00e4t.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-3867\" class=\"comment byuser comment-author-admin_ub bypostauthor odd alt depth-3\">\n<div id=\"comment-3867\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/67426419ead44d5afa132e92685bb460?s=40&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">admin_ub<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">16. Juli 2015 um 08:13<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>bei deinem eigentlichen Fehler kann ich dir auch nicht weiterhelfen\u2026aber eines als Hinweis :<br \/>\neine ISR h\u00e4lt man so kurz wie m\u00f6glich<br \/>\nund Code um den Bildschirm zu beschreiben<br \/>\ngeh\u00f6rt da nicht rein\u2026das f\u00fchrt zu BUGs wenn au\u00dferhalb<br \/>\nder ISR zur gleichen Zeit aufs Display geschrieben wird<\/p>\n<p>warum setzt du nicht einfach ein Flag in der ISR<br \/>\n(das ist eine Zeile Code)<br \/>\nund fragst dieses in der Main-Loop ab<br \/>\n(oder wo auch immer du die Messwerte anzeigen willst)<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Mit dieser Library kann der Ultraschall-Abstands-Sensor vom Typ (HC-SR04) an die STM32F4-CPU angeschlossen werden. Wieder ein DANKE an \u201cJoerg\u201d f\u00fcr den Sensor Das Modul wird an 5V angeschlossen und mit einem 10 us langen Hi-Impuls \u00fcber den Pin \u201cTrigger\u201d zu &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/stm32f4\/komplette-library-liste-stm32f4\/72-hc_sr04-library-stm32f4\/\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":72,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[228,226,9,223,7,227],"class_list":["post-479","page","type-page","status-publish","hentry","category-stm32f4","tag-abstandsmessung","tag-hc-sr04","tag-library","tag-sensor","tag-stm32f4","tag-ultraschall"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/479\/revisions"}],"predecessor-version":[{"id":1611,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/479\/revisions\/1611"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/pages\/144"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}