{"id":1403,"date":"2017-12-16T18:12:44","date_gmt":"2017-12-16T17:12:44","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1403"},"modified":"2017-12-31T00:04:24","modified_gmt":"2017-12-30T23:04:24","slug":"09-spi-lolevel-library-stm32f746","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1403","title":{"rendered":"09-SPI-LoLevel-Library (STM32F746)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1401\" title=\"08-TOUCH-Library (STM32F746)\"><span class=\"meta-nav\">\u2190<\/span> 08-TOUCH-Library (STM32F746)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1405\" title=\"10-UART-Library (STM32F746)\">10-UART-Library (STM32F746) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><br \/>\n<strong>Beschreibung :<\/strong><br \/>\nLoLevel SPI Library f\u00fcr den F746 mit Funktion zum senden und empfangen von Bytes und Arrays.<\/p>\n<p>Eigentlich m\u00fcsste es 6 Libraries geben, weil der F746 6 SPIs hat (stm32_ub_<strong>spi1<\/strong> bis stm32_ub_<strong>spi6<\/strong>). Schaut euch das auf der <a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2016\/01\/Pinbelegung_f746_v102.html\" target=\"_blank\" rel=\"noopener\">Pinbelegung des F746<\/a> an.<\/p>\n<p>Allerdings habe ich bisher nur zwei Libraries erstellt ( stm32_ub_<strong>spi2<\/strong> und stm32_ub_<strong>spi5<\/strong>). Je nachdem welchen SPI-GPIO-Pins verwendet werden sollen (schaut dazu einfach in das header File).<\/p>\n<p>Hier die Beschreibung von <strong>stm32_ub_spi5<\/strong>:<\/p>\n<p><strong>Module :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">stm32_ub_spi5.h, stm32_ub_spi5.c\r\n<\/pre>\n<p><strong>Includes :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">#include \"stm32_ub_system.h\"\r\n<\/pre>\n<p><strong>Enumerationen und Defines:<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ SPI-Mode (Full-Duplex)\r\n\/\/--------------------------------------------------------------\r\ntypedef enum {\r\n  SPI_MODE_0_MSB = 0,  \/\/ CPOL=0, CPHA=0 (MSB-First)\r\n  SPI_MODE_1_MSB,      \/\/ CPOL=0, CPHA=1 (MSB-First)\r\n  SPI_MODE_2_MSB,      \/\/ CPOL=1, CPHA=0 (MSB-First)\r\n  SPI_MODE_3_MSB,      \/\/ CPOL=1, CPHA=1 (MSB-First)\r\n  SPI_MODE_0_LSB,      \/\/ CPOL=0, CPHA=0 (LSB-First)\r\n  SPI_MODE_1_LSB,      \/\/ CPOL=0, CPHA=1 (LSB-First)\r\n  SPI_MODE_2_LSB,      \/\/ CPOL=1, CPHA=0 (LSB-First)\r\n  SPI_MODE_3_LSB       \/\/ CPOL=1, CPHA=1 (LSB-First) \r\n}SPI5_Mode_t;\r\n\r\n\/\/--------------------------------------------------------------\r\n\/\/ SPI-Clock\r\n\/\/ Grundfrequenz (SPI5)= APB2 (APB2=100MHz)\r\n\/\/ M\u00f6gliche Vorteiler = 2,4,8,16,32,64,128,256\r\n\/\/--------------------------------------------------------------\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_2   \/\/ Frq = 50 MHz\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_4   \/\/ Frq = 25 MHz\r\n#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_8   \/\/ Frq = 12,5 MHz\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_16  \/\/ Frq = 6.25 MHz\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_32  \/\/ Frq = 3.125 MHz\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_64  \/\/ Frq = 1.562 MHz\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_128 \/\/ Frq = 781.2 kHz\r\n\/\/#define SPI5_VORTEILER     SPI_BAUDRATEPRESCALER_256 \/\/ Frq = 390.6 kHz\r\n\r\n\/\/--------------------------------------------------------------\r\n\/\/ SPI-GPIO-Pins\r\n\/\/ moegliche Pinbelegung :\r\n\/\/   SCK  : [PF7, PH6]\r\n\/\/   MISO : [PF8, PH7]\r\n\/\/   MOSI : [PF9, PF11]\r\n\/\/--------------------------------------------------------------\r\n#define  SPI5_SCK_PORT     GPIOF\r\n#define  SPI5_SCK_PIN      GPIO_PIN_7\r\n\r\n#define  SPI5_MISO_PORT    GPIOF\r\n#define  SPI5_MISO_PIN     GPIO_PIN_8\r\n\r\n#define  SPI5_MOSI_PORT    GPIOF\r\n#define  SPI5_MOSI_PIN     GPIO_PIN_9\r\n\/\/--------------------------------------------------------------\r\n#define  SPI5_TX_TIMEOUT   1000\r\n<\/pre>\n<p><strong>Funktionen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">ErrorStatus UB_SPI5_Init(SPI5_Mode_t mode);\r\nuint8_t UB_SPI5_SendByte(uint8_t wert);\r\nvoid UB_SPI5_SendArray(uint8_t *tx_buf, uint8_t *rx_buf, uint16_t cnt);\r\n<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 18.12.2017\r\n\/\/ Version  : 1.0\r\n\/\/ Autor    : MB\r\n\/\/ EMail    : -\r\n\/\/ Web      : http:\/\/mikrocontroller.bplaced.net\r\n\/\/ CPU      : STM32F746\r\n\/\/ Board    : STM32F746-Discovery-Board\r\n\/\/ IDE      : OpenSTM32\r\n\/\/ GCC      : 4.9 2015q2\r\n\/\/ Module   : CubeHAL\r\n\/\/ Funktion : Hauptprogramm\r\n\/\/          : Ein Byte per SPI senden und empfangen \r\n\/\/          : SPI-Clock: Grundfrequenz (SPI5)= APB2 (APB2=100MHz)\r\n\/\/          : SPI5_VORTEILER = SPI_BAUDRATEPRESCALER_8 (Frq = 12,5 MHz)\r\n\/\/          : SPI5_SCK_PIN      GPIO_PIN_7\r\n\/\/          : SPI5_MISO_PIN     GPIO_PIN_8\r\n\/\/          : SPI5_MOSI_PIN     GPIO_PIN_9\r\n\/\/--------------------------------------------------------------\r\n\r\n#include \"stm32_ub_system.h\"\r\n#include \"stm32_ub_spi5.h\"\r\n\r\n\/\/--------------------------------------------------------------\r\n\/\/ ein Byte per SPI senden und empfangen\r\n\/\/--------------------------------------------------------------\r\nuint8_t spi_send(uint8_t wert)\r\n{\r\n  uint8_t ret_wert;\r\n\r\n  \/\/ hier Code einf\u00fcgen und\r\n  \/\/ ChipSelect-Pin auf LO legen\r\n\r\n  \/\/ byte senden und empfangen\r\n  ret_wert=UB_SPI5_SendByte(wert);\r\n\r\n  \/\/ hier Code einf\u00fcgen und\r\n  \/\/ ChipSelect-Pin auf HI legen\r\n\r\n  return(ret_wert);\r\n}\r\n\r\nint main(void)\r\n{\r\n  uint8_t wert;\r\n\r\n  \/\/ init vom System\r\n  UB_System_Init();\r\n\r\n  \/\/ SPI5 im Mode0_MSB initialisieren\r\n  UB_SPI5_Init(SPI_MODE_0_MSB);\r\n\r\n  \/\/ den Wert 0x45 per SPI senden\r\n  \/\/ und ein Byte empfangen\r\n  wert=spi_send(0x45);\r\n\r\n  while(1) {\r\n    \/\/ nothing to do\r\n  }\r\n}\r\n<\/pre>\n<p>Hier die Library zum\u00a0<strong>Download :<\/strong><br \/>\n09 = SPI-LoLevel :\u00a0<a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2015\/07\/f746_spi_v100.zip\">f746_spi_v100<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Beschreibung : LoLevel SPI Library f\u00fcr den F746 mit Funktion zum senden und empfangen von Bytes und Arrays. Eigentlich m\u00fcsste es 6 Libraries geben, weil der F746 6 SPIs hat (stm32_ub_spi1 bis stm32_ub_spi6). Schaut euch das auf der Pinbelegung des &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1403\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":182,"menu_order":9,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[130],"tags":[9,49,105],"class_list":["post-1403","page","type-page","status-publish","hentry","category-stm32f746","tag-library","tag-spi","tag-stm32f746"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1403","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=1403"}],"version-history":[{"count":4,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1403\/revisions"}],"predecessor-version":[{"id":1552,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1403\/revisions\/1552"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/182"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}