{"id":233,"date":"2017-11-23T00:04:58","date_gmt":"2017-11-22T23:04:58","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=233"},"modified":"2023-03-04T23:49:19","modified_gmt":"2023-03-04T22:49:19","slug":"17-spi_lis302dl-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=233","title":{"rendered":"17-SPI_LIS302DL-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=231\" title=\"16-SPI_MAX5250-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 16-SPI_MAX5250-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=235\" title=\"18-I2C_LoLevel-Library (STM32F4)\">18-I2C_LoLevel-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Auf dem Discovery-Board ist ein 3Achs-Beschleunigungs-Sensor eingebaut (LIS302DL)<\/p>\n<p>Hinweis : auf \u201cneuen\u201d Discovery-Boards ist der LIS3DSH best\u00fcckt<br \/>\nf\u00fcr den gibt es eine extra Library hier im Blog.<\/p>\n<p>Mit diesem Sensor k\u00f6nnen die Beschleunigungskr\u00e4fte der X-, Y-, Z-Achse gemessen werden.<\/p>\n<p>Der Sensor hat eine Genauigkeit von 8bit und eine umschaltbare\u00a0Aufl\u00f6sung von entweder +\/- 2g oder +\/- 8g<\/p>\n<p>Mit dieser Library kann der Sensor sehr leicht benutzt werden. Man ruft einfach die Funktion \u201cUB_LIS302_Read()\u201d zyklisch auf und erh\u00e4lt als Ergebnis die aktuellen Beschleunigungswerte in mg aller 3 Achsen als Struktur zur\u00fcck.<br \/>\n(bei 2g Aufl\u00f6sung also Werte von -2000mg bis +2000mg)<\/p>\n<p>Der Sensor kann eigentlich im Interrupt-Betrieb benutzt werden und auch Klick-Events bzw. Doppelklick-Events auswerten \u2026aber darauf hab ich wegen der \u00dcbersichtlichkeit verzichtet. Wer diese Funktionen will, soll sich bei mir melden.<\/p>\n<p>Vorsicht : im UserManual vom Discovery-Board ist ein Fehler, der ChipSelect-Pin vom LIS302DL liegt an PE3 (nicht wie beschrieben an PE2)<\/p>\n<p>Der Sensor h\u00e4ngt am SPI1 aus dem Grund wird die SPI1-Lib auch ben\u00f6tigt.<\/p>\n<p><strong>Beispielbild :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/03\/lis302.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-718\" src=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/03\/lis302-179x300.jpg\" alt=\"lis302\" width=\"179\" height=\"300\" \/><\/a><\/p>\n<p><strong>Benutzte Pins :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">SCK an PA5\r\nMOSI an PA7\r\nMISO an PA6\r\nChipSelect an PE3<\/pre>\n<p><strong>Voraussetzungen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : GPIO\r\nBenutzte Librarys : STM32_UB_SPI1<\/pre>\n<p><strong>Enumerationen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef enum {\r\n  SCALE_2G =0,    \/\/ Aufl\u00f6sung +\/- 2g\r\n  SCALE_8G        \/\/ Aufl\u00f6sung +\/- 8g\r\n}LIS302_SCALE_t;<\/pre>\n<p><strong>.<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef enum {\r\n  FILTER_OFF =0,  \/\/ High-Pass Filter abgeschaltet\r\n  FILTER_2Hz,     \/\/ Filter eingeschaltet (2 Hz)\r\n  FILTER_1Hz,     \/\/ Filter eingeschaltet (1 Hz)\r\n  FILTER_500mHz,  \/\/ Filter eingeschaltet (0,5 Hz)\r\n  FILTER_250mHz   \/\/ Filter eingeschaltet (0,25 Hz) \r\n}LIS302_FILTER_t;<\/pre>\n<p><strong>Funktionen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">ErrorStatus UB_LIS302_Init(LIS302_SCALE_t scale);  \/\/ zum initialisieren des LIS302DL\r\nvoid UB_LIS302_Read(void);                         \/\/ zum auslesen der Beschleunigungswerte\r\nvoid UB_LIS302_SetFilter(LIS302_FILTER_t filter);  \/\/ zum einstellen des Filters<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 06.03.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.0\r\n\/\/ Module   : CMSIS_BOOT, M4_CMSIS_CORE\r\n\/\/ Funktion : Demo der LIS302DL 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_lis302dl.h\"\r\n#include \"stm32_ub_led.h\"\r\n\r\nint main(void)\r\n{\r\n  ErrorStatus check;\r\n\r\n  SystemInit(); \/\/ Quarz Einstellungen aktivieren\r\n\r\n  UB_Led_Init(); \/\/ LEDs initialisieren\r\n\r\n  \/\/ LIS302 initialisieren (mit +\/- 2G Aufl\u00f6sung)\r\n  check=UB_LIS302_Init(SCALE_2G);\r\n\r\n  if(check==ERROR) {\r\n    \/\/ LIS302 wurde nicht gefunden\r\n    \/\/ rote und gr\u00fcne LED einschalten\r\n    UB_Led_On(LED_RED);\r\n    UB_Led_On(LED_GREEN);\r\n    \/\/ STOP\r\n    while(1);\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    \/\/ LIS302 auslesen\r\n    UB_LIS302_Read();\r\n    \/\/ wenn Platine nach links geneigt wird, rote LED einschalten\r\n    if(LIS302.y_achse&gt;250) UB_Led_On(LED_RED); else UB_Led_Off(LED_RED);\r\n    \/\/ wenn Platine nach rechts geneigt wird, gruene LED einschalten\r\n    if(LIS302.y_achse&lt;-250) UB_Led_On(LED_GREEN); else UB_Led_Off(LED_GREEN);\r\n    \/\/ wenn Platine nach hinten geneigt wird, blaue LED einschalten\r\n    if(LIS302.x_achse&gt;250) UB_Led_On(LED_BLUE); else UB_Led_Off(LED_BLUE);\r\n    \/\/ wenn Platine nach vorne geneigt wird, orange LED einschalten\r\n    if(LIS302.x_achse&lt;-250) UB_Led_On(LED_ORANGE); else UB_Led_Off(LED_ORANGE);\r\n  }\r\n}\r\n<\/pre>\n<p>Hier die Library zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/03\/ub_stm32f4_spi_lis302dl_v100.zip\">ub_stm32f4_spi_lis302dl_v100<\/a><\/p>\n<p>Hier der komplette CooCox-Projektordner zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2013\/03\/Demo_17_SPI_LIS302DL.zip\">Demo_17_SPI_LIS302DL<\/a><\/p>\n<h3 id=\"comments-title\">7 Antworten auf <em>17-SPI_LIS302DL-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-1210\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-1210\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/07f18cfeca54e47cd5c97c7498dba776?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\"><a class=\"url\" href=\"http:\/\/djelko.de\/\" rel=\"external nofollow\">DjElko<\/a><\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">25. Dezember 2013 um 20:46<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Danke f\u00fcr Deine libs!!!<br \/>\nEcht spitze!<\/p>\n<p>Bei dieser lib erkennt der STM32F4 allerdings meinen Beschleunigungschip nicht<br \/>\n(rote + gr\u00fcne Led leuchten)\u2026<br \/>\nWoran k\u00f6nnte das liegen?<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-1215\" class=\"comment byuser comment-author-admin_ub bypostauthor odd alt depth-2\">\n<div id=\"comment-1215\">\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\">27. Dezember 2013 um 10:42<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>etnweder hast du die SPI-1 schon in einem anderen Mode initialisiert (das wird gepr\u00fcft) oder dein LIS302 liefert eine andere Kennung als \u201c0x3B\u201d zur\u00fcck. Setzt mal einen Breakpoint an den Anfang der Init-Funktion und geht die Schritt f\u00fcr Schritt durch, dann siehst du wo und warum er rausfliegt.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-1241\" class=\"comment even thread-odd thread-alt depth-1\">\n<div id=\"comment-1241\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/07f18cfeca54e47cd5c97c7498dba776?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\"><a class=\"url\" href=\"http:\/\/djelko.de\/\" rel=\"external nofollow\">DjElko<\/a><\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">2. Januar 2014 um 15:37<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hmmm. Der fliegt bei der \u00dcberpr\u00fcfung der ID raus\u2026<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-1242\" class=\"comment odd alt thread-even depth-1\">\n<div id=\"comment-1242\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/07f18cfeca54e47cd5c97c7498dba776?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\"><a class=\"url\" href=\"http:\/\/djelko.de\/\" rel=\"external nofollow\">DjElko<\/a><\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">2. Januar 2014 um 15:56<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Ich habe jetzt mal die \u00fcberpr\u00fcfung der ID rausgeschmissen -&gt; es funktioniert!<br \/>\nDanke!<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-1259\" class=\"comment even thread-odd thread-alt depth-1\">\n<div id=\"comment-1259\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/f938ce7bc7378c02a3cf2a24c8d30637?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\">Joe<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">11. Januar 2014 um 02:01<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Wow, vielen Dank f\u00fcr die tollen Anleitungen und Libraries <img decoding=\"async\" class=\"wp-smiley\" src=\"wp-includes\/images\/smilies\/icon_smile.gif\" alt=\":-)\" \/> )<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-1662\" class=\"comment odd alt thread-even depth-1\">\n<div id=\"comment-1662\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/7d1e06223b07c9612741b0b3cf73c778?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\">dar<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">7. Mai 2014 um 19:46<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hi,<br \/>\nYou have made the greatest libraries!!!<\/p>\n<p>one feed back I would like to give:<\/p>\n<p>the newer Discovery boards have the LIS3DSH accelerometer (revision C with MMB997C on them) this accelerometer has 0X3F for the Who_Am_I (register 0F) byte.<\/p>\n<p>So, just change the #define LIS302_ID to 0X3F in the stm32_ub_lis302dl.h<br \/>\nit all works perfect.<\/p>\n<p>keep up the good work!!<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-1720\" class=\"comment byuser comment-author-admin_ub bypostauthor even depth-2\">\n<div id=\"comment-1720\">\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\">17. Mai 2014 um 19:28<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Thanks for the hint. The LIS3DSH is a little bit different in the register settings so i have made a new library. Please check the new LIS3DSH-Lib. I cant test it by my own.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Auf dem Discovery-Board ist ein 3Achs-Beschleunigungs-Sensor eingebaut (LIS302DL) Hinweis : auf \u201cneuen\u201d Discovery-Boards ist der LIS3DSH best\u00fcckt f\u00fcr den gibt es eine extra Library hier im Blog. Mit diesem Sensor k\u00f6nnen die Beschleunigungskr\u00e4fte der X-, Y-, Z-Achse gemessen werden. Der &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=233\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":17,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[9,151,49,7],"class_list":["post-233","page","type-page","status-publish","hentry","category-stm32f4","tag-library","tag-lis302dl","tag-spi","tag-stm32f4"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/233","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=233"}],"version-history":[{"count":4,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/233\/revisions"}],"predecessor-version":[{"id":3667,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/233\/revisions\/3667"}],"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=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}