{"id":525,"date":"2017-11-25T15:05:33","date_gmt":"2017-11-25T14:05:33","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=525"},"modified":"2017-12-30T19:41:02","modified_gmt":"2017-12-30T18:41:02","slug":"90-i2c_gy271-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=525","title":{"rendered":"90-I2C_GY271-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=523\" title=\"89-FATFS_SPI-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 89-FATFS_SPI-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=527\" title=\"91-SPI-DMA-Library (STM32F4)\">91-SPI-DMA-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Wer ein GY271-Modul (3Achs Digital-Kompass-Modul mit\u00a0HMC5883L-Chip) ansteuern will, kann diese Library benutzen.<\/p>\n<p>An dieser Stelle ein DANKE an\u00a0\u201d<strong>Joerg<\/strong>\u201d der mir den Sensor zugesendet hat.<\/p>\n<p>Es gibt eine Funktion zum initialisieren und eine Funktion um die Daten vom Sensor<br \/>\nauszulesen (diese Funktion muss gepollt werden) .<\/p>\n<p>Nach dem auslesen steht der Status vom Sensor und der aktuelle Winkel<br \/>\n(als Gradwert 0 bis 359) in einer Struktur.<\/p>\n<p>Der Messbereich kann mit einer 3ten Funktion eingestellt werden<br \/>\n(von +\/- 0,8 Gauss bis +\/- 8Gauss)<\/p>\n<p>Und per START\/STOP-Calibration kann ein Kalibrations Modus realisiert werden.<br \/>\nDer Sensor muss in diesem Modus in alle Lagen gedreht werden um die Min-Max-Werte<br \/>\nzu erfassen, die f\u00fcr die Nullpunkt Kalibration notwendig sind)<\/p>\n<p>Es wird die I2C-LoLevel-Library benutzt (mit I2C1)<\/p>\n<p>Hinweis-1 : Mein Sensor Funktioniert nach der Kalibration komischerweise besser, wenn die Platine vom Modul nicht waagrecht sondern senkrecht gehalten wird. Keine Ahnung warum.<\/p>\n<p>Hinweis-2 : Der Sensor reagiert sehr empfindlich gegen alles metalische (auch die Zuleitungen und andere Elektronik) und gegen elektrische Magnetefelder<br \/>\n(daf\u00fcr ist der Magnetfeld-Sensor ja da <img decoding=\"async\" class=\"wp-smiley\" src=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif\" alt=\":-)\" \/><\/p>\n<p>Hinweis-3 : F\u00fcr die Umrechnung der Rohdaten in einen Winkelwert wird die C-Funktion \u201catan2(\u2026)\u201d benutzt. Daf\u00fcr wird die included. Um diese Bibliothek beim compilieren hinzuzuf\u00fcgen, muss bei CoIDE unter \u201cConfiguration\/Link\/Misc Controls\u201d der Schalter \u201c-lm\u201d manuell hinzugef\u00fcgt werden\u00a0!!<\/p>\n<p><strong>Beispielbild :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2014\/12\/gy_271.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-4580\" src=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2014\/12\/gy_271-300x179.jpg\" alt=\"gy_271\" width=\"300\" height=\"179\" \/><\/a><\/p>\n<p><strong>Benutzte Pins :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">SCL an PB6\r\nSDA an PB7<\/pre>\n<p><strong>Voraussetzungen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : keine\r\nBenutzte Librarys : STM32_UB_I2C1<\/pre>\n<p><strong>Enumerationen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">  HMC5883_0G8 = 0,  \/\/ +\/- 0,88 Gauss\r\n  HMC5883_1G3,      \/\/ +\/- 1,3 Gauss (default)\r\n  HMC5883_1G9,      \/\/ +\/- 1,9 Gauss\r\n  HMC5883_2G5,      \/\/ +\/- 2,5 Gauss\r\n  HMC5883_4G0,      \/\/ +\/- 4,0 Gauss\r\n  HMC5883_4G7,      \/\/ +\/- 4,7 Gauss\r\n  HMC5883_5G6,      \/\/ +\/- 5,6 Gauss\r\n  HMC5883_8G1       \/\/ +\/- 8,1 Gauss<\/pre>\n<p><strong>Struktur :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef struct {\r\n  HMC5883_STATUS_t status;   \/\/ status vom Sensor\r\n  uint16_t winkel;           \/\/ Winkel in Grad [0 bis 359]\r\n}HMC5883_t;\r\nHMC5883_t HMC5883;<\/pre>\n<p><strong>Funktionen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">ErrorStatus UB_HMC5883_Init(void);                        \/\/ zum initialisieren vom Sensor\r\nErrorStatus UB_HMC5883_Read(void);                        \/\/ zum auslesen vom Sensor\r\nErrorStatus UB_HMC5883_SetScale(HMC5883_SCALE_t scale);   \/\/ zum einstellen vom Messbereich\r\nvoid UB_HMC5883_Start_Calibration(void);                  \/\/ zum starten der Kalibration\r\nvoid UB_HMC5883_Stop_Calibration(void);                   \/\/ zum stoppen der Kalibration<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 21.12.2014\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 HMC5883-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_hmc5883.h\"\r\n#include \"stm32_ub_led.h\"\r\n\r\nint main(void)\r\n{\r\n  ErrorStatus check;\r\n  uint8_t led_mode=1;\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 HMC5883\r\n  check=UB_HMC5883_Init();\r\n  if(check!=SUCCESS) {\r\n    \/\/ bei einem Fehler gruen und rot einschalten\r\n    UB_Led_On(LED_RED);\r\n    UB_Led_On(LED_GREEN);\r\n    while(1); \/\/ stop\r\n  }\r\n  else {\r\n    \/\/ Sensor auf \"unempfindlich\" einstellen\r\n    UB_HMC5883_SetScale(HMC5883_8G1);\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    \/\/ sensor pollen\r\n    UB_HMC5883_Read();\r\n    \/\/ check ob Sensor Daten ok sind\r\n    if(HMC5883.status==HMC5883_OK) {\r\n      \/\/ zuerst alle LEDs auschalten\r\n      UB_Led_Off(LED_GREEN);\r\n      UB_Led_Off(LED_RED);\r\n      UB_Led_Off(LED_ORANGE);\r\n      UB_Led_Off(LED_BLUE);\r\n      \/\/ dann eine LED je nach Winkel einschalten\r\n      if((HMC5883.winkel&gt;=60) &amp;&amp; (HMC5883.winkel&lt;=120)) led_mode=1; if((HMC5883.winkel&gt;=150) &amp;&amp; (HMC5883.winkel&lt;=210)) led_mode=2; if((HMC5883.winkel&gt;=240) &amp;&amp; (HMC5883.winkel&lt;=300)) led_mode=3; if((HMC5883.winkel&gt;=330) || (HMC5883.winkel&lt;=30)) led_mode=4;\r\n\r\n      if(led_mode==1) UB_Led_On(LED_BLUE);\r\n      if(led_mode==2) UB_Led_On(LED_GREEN);\r\n      if(led_mode==3) UB_Led_On(LED_ORANGE);\r\n      if(led_mode==4) UB_Led_On(LED_RED);\r\n    }\r\n    else {\r\n      \/\/ bei einem Fehler gruen und rot einschalten\r\n      UB_Led_On(LED_RED);\r\n      UB_Led_On(LED_GREEN);\r\n      UB_Led_Off(LED_ORANGE);\r\n      UB_Led_Off(LED_BLUE);\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\/2014\/12\/ub_stm32f4_i2c_hmc5883_v100.zip\">ub_stm32f4_i2c_hmc5883_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\/2014\/12\/Demo_90_I2C_HMC5883L.zip\">Demo_90_I2C_HMC5883L<\/a><\/p>\n<hr \/>\n<h3 id=\"comments-title\">3 Antworten auf <em>90-I2C_GY271-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-2778\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-2778\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/af5be9fa3f95b3ec9c424ed130b7f2d3?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\">Cortex-Einsteiger<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">2. Januar 2015 um 14:34<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>wieder eine tolle Lib, danke!<br \/>\nHabe den Sensor schon einige Monate in der Schublade liegen gehabt, da er mit meiner eigenen Software aber nicht stabil lief, blieb er dort.<\/p>\n<p>Demoprogramm aufgespielt, l\u00e4uft <img decoding=\"async\" class=\"wp-smiley\" src=\"wp-includes\/images\/smilies\/icon_smile.gif\" alt=\":)\" \/><br \/>\nIm n\u00e4chsten Schritt noch die Libs f\u00fcr Display, Font und Stringwandlung eingef\u00fcgt, funktioniert perfekt, DANKE, dass du deine Arbeit mit uns teilst.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-4203\" class=\"comment odd alt thread-odd thread-alt depth-1\">\n<div id=\"comment-4203\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/af623af1882360d3bb1d872ca4250ab2?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\">Cristian<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">2. Oktober 2015 um 19:27<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hallo! Gro\u00dfen Beitrag !! Haben Sie mit der GY-521-Modul gearbeitet? (Gyroskop + Beschleunigungsmesser)<br \/>\nHerzlichen Dank!<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-4207\" class=\"comment byuser comment-author-admin_ub bypostauthor even depth-2\">\n<div id=\"comment-4207\">\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\">4. Oktober 2015 um 10:34<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>nein.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Wer ein GY271-Modul (3Achs Digital-Kompass-Modul mit\u00a0HMC5883L-Chip) ansteuern will, kann diese Library benutzen. An dieser Stelle ein DANKE an\u00a0\u201dJoerg\u201d der mir den Sensor zugesendet hat. Es gibt eine Funktion zum initialisieren und eine Funktion um die Daten vom Sensor auszulesen (diese &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=525\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":90,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[246,248,98,247,9,7],"class_list":["post-525","page","type-page","status-publish","hentry","category-stm32f4","tag-gy271","tag-hmc5883l","tag-i2c","tag-kompass","tag-library","tag-stm32f4"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/525","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=525"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/525\/revisions"}],"predecessor-version":[{"id":1633,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/525\/revisions\/1633"}],"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=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}