{"id":421,"date":"2017-11-24T23:15:10","date_gmt":"2017-11-24T22:15:10","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=421"},"modified":"2017-12-30T19:36:18","modified_gmt":"2017-12-30T18:36:18","slug":"47-mp45dt02-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=421","title":{"rendered":"47-MP45DT02-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=419\" title=\"46-IRSND-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 46-IRSND-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=423\" title=\"48-USB_HID-Library (STM32F4)\">48-USB_HID-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit dieser Library kann das MEMS-Micro (MP45DT02) vom Discovery-Board benutzt werden um Sound aufzunehmen und als WAV-File auf einer SD-Karte zu speichern.<\/p>\n<p>Die Samplerate ist auf 16kHz und 16bit eingestellt. Wobei die Abtastrate vom Micro bei 64kHz liegt, die Werte aber noch gefiltert werden.<\/p>\n<p>Der benutzte Software Filter ist von STM und liegt nur als compilierte Library vor. Dieses File muss aus dem Grund in der CoIDE im Linker hinzugef\u00fcgt werden.<\/p>\n<p>Hinweis : Der I2S-Clock und der notwendige PLL muss nicht im \u201csystem_stm32f4xx.c-File\u201d eingestellt werden, das wird von der Library erledigt.<\/p>\n<p>Bei meinen Test war die Aufnahmequalit\u00e4t sehr schlecht, ich hatte aber keine Lust da noch viel Zeit zu investieren.<\/p>\n<p>Theoretisch k\u00f6nnen die Daten auch im RAM oder auf USB gespeichert, wer das will.<\/p>\n<p>Wegen dem speichern auf SD-Karte wird die FATFS-Lib benutzt.<\/p>\n<p><strong>Benutzte Pins :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">PB10 = Clock\r\nPC3  = Data<\/pre>\n<p><strong>Voraussetzungen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : SPI, MISC\r\nBenutzte Librarys : STM32_UB_FATFS\r\n<\/pre>\n<p><strong>Enumerationen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef enum {\r\n  MP45DT02_REC_OK = 0,\r\n  MP45DT02_INIT_ERR,\r\n  MP45DT02_FILE_ERR\r\n}MP45DT02_ERR_t;<\/pre>\n<p><strong>Funktionen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">ErrorStatus UB_MP45DT02_Init(void);                        \/\/ zum initialisieren vom MP45DT02\r\nMP45DT02_ERR_t UB_MP45DT02_RecordStart(const char* name);  \/\/ zum starten der Aufnahme\r\nvoid UB_MP45DT02_RecordLoop(void);                         \/\/ muss zyklisch aufgerufen werden\r\nvoid UB_MP45DT02_RecordStop(void);                         \/\/ zum beenden der Aufnahme<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 15.06.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 MP45DT02-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_mp45dt02.h\"\r\n#include \"stm32_ub_led.h\"\r\n\r\nint main(void)\r\n{\r\n  uint32_t n,m;\r\n\r\n  SystemInit(); \/\/ Quarz Einstellungen aktivieren\r\n\r\n  UB_Led_Init(); \/\/ Init der LEDs\r\n  UB_MP45DT02_Init();  \/\/ Init vom MP45DT02\r\n  UB_Fatfs_Init(); \/\/ Init vom FATFS-System\r\n\r\n  \/\/ Test ob SD-Karte eingelegt\r\n  if(UB_Fatfs_CheckMedia(MMC_0)==FATFS_OK) {\r\n    \/\/ Karte mounten\r\n    if(UB_Fatfs_Mount(MMC_0)==FATFS_OK) {\r\n      UB_Led_On(LED_GREEN);\r\n\r\n      \/\/ File anlegen und Aufnahme starten\r\n      UB_MP45DT02_RecordStart(\"test16k.wav\");\r\n\r\n      \/\/ ein paar Sekunden aufnehmen\r\n      for(n=0;n&lt;10;n++) {\r\n        UB_Led_Toggle(LED_BLUE);\r\n        for(m=0;m&lt;500000;m++) {\r\n          \/\/ Loop-Funktion aufrufen !! WICHTIG !!\r\n          UB_MP45DT02_RecordLoop();\r\n        }\r\n      }\r\n\r\n      \/\/ Aufnahme beenden\r\n      UB_MP45DT02_RecordStop();\r\n\r\n      \/\/ Karte unmounten\r\n      UB_Fatfs_UnMount(MMC_0);\r\n\r\n      UB_Led_Off(LED_GREEN);\r\n\r\n    }\r\n    else UB_Led_On(LED_RED);\r\n  }\r\n  else UB_Led_On(LED_RED);\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\/06\/ub_stm32f4_mp45dt02_v100.zip\">ub_stm32f4_mp45dt02_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\/06\/Demo_47_MP45DT02.zip\">Demo_47_MP45DT02<\/a><\/p>\n<h3 id=\"comments-title\">3 Antworten auf <em>47-MP45DT02-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-2534\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-2534\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/6c2e282b2877a9ee9c0b97d0714986c7?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\">thomas<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">23. November 2014 um 04:23<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hi Uwe,<\/p>\n<p>Um stereo von zwei MP45DT02 aufzunehmen, wie wird dann SPI2 configuriert? I2S_InitStructure.I2S_CPOL kann nur I2S_CPOL_High oder I2S_CPOL_Low annehmen. Wenn ich das MP45DT02 Datenblatt richtig lese muss man aber einen interrupt f\u201dur die aufsteigende UND abfallende Flanke des Taktes erzeugen, wenn man zwei MP45DT02 in Stereo mode an einer Datenleitung hat. Wie wird das erreicht?<\/p>\n<p>Im voraus Danke f\u201dur Deine Antwort, und vielen Dank f\u201dur all die n\u201dutzlichen Beispiele. Gruss, thomas<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-4216\" class=\"comment odd alt depth-2\">\n<div id=\"comment-4216\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/af560470d63888972020af59558bd98f?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\">Tobi<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">7. Oktober 2015 um 16:10<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hallo,<\/p>\n<p>auch wenn das alles scho etwas her ist:<br \/>\nWenn ich das richtig verstehe, geht das gar nicht. Bei meinem Testaufbau bekomme ich die Daten per DMA, aber immer nur vom rechten Kanal, egal wie ich I2S_CPOL einstelle. Der linke Kanal liefert bei mir nie Daten.<\/p>\n<p>Ich verstehe CPOL auch so, das hier nur eingestellt wird, wo die Leitung h\u00e4ngen soll, wenn nichts \u00fcbertragen wird (idle) und egal wie CPOL eingestellt ist, immer mit der steigenden Flanke von CLK \u00fcbertragen wird.<\/p>\n<p>Eigentlich w\u00fcrde ich auch gerne wissen, ob es nicht doch geht in Stereo mit der I2S Schnittstelle une zwei PDM Micros aufzunehmen.<\/p>\n<p>Wei\u00df da jemand was dazu?<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-4485\" class=\"comment even thread-odd thread-alt depth-1\">\n<div id=\"comment-4485\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/4501609d83043839b7430a1f82614f92?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\">Tom<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">28. Dezember 2015 um 22:31<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hallo,<br \/>\ndie Qualit\u00e4t des Audiosignals lie\u00df sich bei mir durch deaktivieren der Tiefpassfilterfrequenz (###.LP = 0) erheblich verbessern, dann wird jedoch hochfrequentes Rauschen h\u00f6rbar. Vorher knackte bei mir das Signal in zeitlich konstanten Intervallen. Ich hab die Tonsignale direkt \u00fcber UDP an meinen Rechner geschickt und \u201clive\u201d mitgeh\u00f6rt. \u2013 funktionierte toll \u2013 Falls wer Probleme mit der vorkompilierten Datei hat (HW-FPU \u2013 #### uses VFP register arguments, lib\u2026 does not) kann man einfach die .s und .h-Datei von \u201chttps:\/\/github.com\/piratfm\/codec2_m4f\/tree\/master\/lib\/PDM_filter\u201d einbinden (einfach einf\u00fcgen).<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Mit dieser Library kann das MEMS-Micro (MP45DT02) vom Discovery-Board benutzt werden um Sound aufzunehmen und als WAV-File auf einer SD-Karte zu speichern. Die Samplerate ist auf 16kHz und 16bit eingestellt. Wobei die Abtastrate vom Micro bei 64kHz liegt, die Werte &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=421\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":47,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[9,196,195,197,7],"class_list":["post-421","page","type-page","status-publish","hentry","category-stm32f4","tag-library","tag-mems-micro","tag-mi","tag-mp45dt02","tag-stm32f4"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/421","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=421"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/421\/revisions"}],"predecessor-version":[{"id":1586,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/421\/revisions\/1586"}],"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=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}