{"id":456,"date":"2017-11-24T23:43:11","date_gmt":"2017-11-24T22:43:11","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=456"},"modified":"2017-12-30T19:37:55","modified_gmt":"2017-12-30T18:37:55","slug":"62-onewire_lolevel-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=456","title":{"rendered":"62-OneWire_LoLevel-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=454\" title=\"61-LCD_Nokia5110-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 61-LCD_Nokia5110-Library (STM32F4)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=458\" title=\"63-OneWire_DS18XX-Library (STM32F4)\">63-OneWire_DS18XX-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Hier eine Library um mit dem STM32F4 einen OneWire-Bus steuern zu k\u00f6nnen.<br \/>\n(One-Wire =&gt; Eindrahtbus =&gt; 1-Wire-Bus =&gt; ist eine serielle Schnittstelle mit nur einer Datenleitung)<\/p>\n<p>Der STM32F4 fungiert hierbei als \u201cMaster\u201d und kann prinzipiell unendlich viele Slaves \u00fcber die eine Datenleitung steuern. Die Slaves werden durch einen 8Byte RomCode unterschieden der in jedem Slave unterschiedlich ist.<\/p>\n<p>Der Datenpin ist als \u201cOpenDrain-Output\u201d geschaltet und es muss zwingend ein externer PullUp (gegen 3,3V) von ca. 4k7 eingebaut werden. (Im H-File wird der Pin festgelegt)<\/p>\n<p>Um zu erkennen ob \u00fcberhaupt ein Slave am Datenbus h\u00e4ngt, gibt es die Funktion \u201cUB_OneWire_ResetSequenz\u201d die gleichzeitig alle Slaves in einen definierten Zustand bringt.<\/p>\n<p>Die LoLevel-Lib besitzt die grundlegenden Funktionen zum lesen\/schreiben eines Bits oder eines Bytes.<\/p>\n<p>Zum Adressieren eines Slaves muss dessen RomCode bekannt sein. Um diesen auszulesen gibt es die Funktion \u201cUB_OneWire_ReadRomCode\u201d. (Bei dieser Funktion darf nur ein Slave am Bus h\u00e4ngen). Wer den RomCode als String sehen will, kann ihn per \u201cUB_OneWire_RomCode2Str\u201d umwandeln.<\/p>\n<p>Damit der Code \u00fcbersichtlicher bleibt, kann der 8Byte RomCode als String der Funktion \u201cUB_OneWire_Str2RomCode\u201d \u00fcbergeben werden. Diese wandelt den String dann in 8 einzelne Bytes um. (siehe Quellcode vom OneWire DS1822 Temp-Sensor)<\/p>\n<p><strong>Pinbelegung :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">PD3 = Datenpin<\/pre>\n<p><strong>Voraussetzungen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : GPIO, TIM, MISC, (Retarget Printf)\r\nBenutzte Librarys : keine<\/pre>\n<p><strong>Funktionen \u00a0:<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">void UB_OneWire_Init(void);                         \/\/ init der Library\r\nErrorStatus UB_OneWire_ResetSequenz(void);          \/\/ Reset-Sequenz\r\nErrorStatus UB_OneWire_ReadRomCode(void);           \/\/ lie\u00dft den RomCode\r\nvoid UB_OneWire_WriteByte(uint8_t wert);            \/\/ schreibt ein Byte\r\nuint8_t UB_OneWire_ReadByte(void);                  \/\/ lie\u00dft ein Byte\r\nvoid UB_OneWire_WriteBitLo(void);                   \/\/ schreibt ein Bit (Lo)\r\nvoid UB_OneWire_WriteBitHi(void);                   \/\/ schreibt ein Bit (Hi)\r\nBitAction UB_OneWire_ReadBit(void);                 \/\/ lie\u00dft ein Bit\r\nErrorStatus UB_OneWire_Str2RomCode(char *rom_code); \/\/ zum umwandeln vom String in RomCode\r\nvoid UB_OneWire_RomCode2Str(char *rom_code);        \/\/ zum umwandeln von RomCode in String<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 29.09.2013\r\n\/\/ Version  : 1.1\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 OneWire-LoLevel-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_onewire.h\"\r\n#include \"stm32_ub_led.h\"\r\n\r\nint main(void)\r\n{\r\n  ErrorStatus check;\r\n  char rom_code[20];\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 OneWire-Bus\r\n  UB_OneWire_Init();\r\n\r\n  \/\/ test ob ein OneWire-Slave angeschlossen ist\r\n  check=UB_OneWire_ResetSequenz();\r\n\r\n  if(check==SUCCESS) {\r\n    UB_Led_On(LED_GREEN);\r\n    \/\/ auslesen vom 8Byte RomCode\r\n    \/\/ es darf nur EIN Slave angeschlossen sein !\r\n    UB_OneWire_ReadRomCode();\r\n    \/\/ RomCode in String wandeln\r\n    \/\/ (String kann per Debugger angezeigt werden)\r\n    UB_OneWire_RomCode2Str(rom_code);\r\n  }\r\n  else {\r\n    UB_Led_On(LED_RED);\r\n  }\r\n\r\n  while(1)\r\n  {\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\/09\/ub_stm32f4_onewire_v101.zip\">ub_stm32f4_onewire_v101<\/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\/09\/Demo_62_OneWire_LoLevel.zip\">Demo_62_OneWire_LoLevel<\/a><\/p>\n<hr \/>\n<h3 id=\"comments-title\">5 Antworten auf <em>62-OneWire_LoLevel-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-2787\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-2787\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/3ba790f2c0d8ccdce007d213e630681b?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\">Thamanoon<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">8. Januar 2015 um 04:28<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Thank you very much for your code, I test the code with stm32f4discovery connect to DS18S20+, it\u2019s work propery. Then I try to modify the code to use with stm32f103rb, it\u2019s not work now.<br \/>\n<a href=\"http:\/\/www.electoday.com\/index.php\/topic,12412.0.html\" rel=\"nofollow\">http:\/\/www.electoday.com\/index.php\/topic,12412.0.html<\/a><\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2793\" class=\"comment byuser comment-author-admin_ub bypostauthor odd alt depth-2\">\n<div id=\"comment-2793\">\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\">8. Januar 2015 um 11:30<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>please check the lenght of the signals with a oscilloscope.<br \/>\nthe correct frq is important to work properly.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-2815\" class=\"comment even thread-odd thread-alt depth-1\">\n<div id=\"comment-2815\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/3ba790f2c0d8ccdce007d213e630681b?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\">Thamanoon<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">11. Januar 2015 um 13:53<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>I use Systick instead of TIM2 for a delay function, it\u2019s work now. Do you think about it? (My program is inside my link) Thanks.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2816\" class=\"comment byuser comment-author-admin_ub bypostauthor odd alt depth-2\">\n<div id=\"comment-2816\">\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\">11. Januar 2015 um 14:07<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>TIM2 ?\u2026 in the Library TIM7 is used<br \/>\nand i dont search your failure\u2026but when the function with systick is ok\u2026then you have found the problem\u2026the TIM7 ist not working correct , means runns with the wrong frequenz<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2818\" class=\"comment even depth-3\">\n<div id=\"comment-2818\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/3ba790f2c0d8ccdce007d213e630681b?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\">Thamanoon<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">11. Januar 2015 um 15:07<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>I modified your code to use with stm32f103rb and use TIM2 instead of TIM7, I think TIM2 with interrupt in short period(1us) has overhead and extend the time more than 1us, with no problem on stm32f4idscovery that has high speed clock. I will use logic analyzer to check the signal compare between the used of TIM2 and Systick. Thank for your suggestion, I forgot to use the measuring tool.<\/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>Hier eine Library um mit dem STM32F4 einen OneWire-Bus steuern zu k\u00f6nnen. (One-Wire =&gt; Eindrahtbus =&gt; 1-Wire-Bus =&gt; ist eine serielle Schnittstelle mit nur einer Datenleitung) Der STM32F4 fungiert hierbei als \u201cMaster\u201d und kann prinzipiell unendlich viele Slaves \u00fcber die &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=456\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":62,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[9,208,7],"class_list":["post-456","page","type-page","status-publish","hentry","category-stm32f4","tag-library","tag-one-wire","tag-stm32f4"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=456"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/456\/revisions"}],"predecessor-version":[{"id":1601,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/456\/revisions\/1601"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/144"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}