{"id":315,"date":"2017-11-23T20:59:43","date_gmt":"2017-11-23T19:59:43","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=315"},"modified":"2017-12-30T19:30:27","modified_gmt":"2017-12-30T18:30:27","slug":"16-spi_lolevel_halfduplex-library-stm32f429","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=315","title":{"rendered":"16-SPI_LoLevel_HalfDuplex-Library (STM32F429)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=313\" title=\"15-Touch_STMPE811-Library (STM32F429)\"><span class=\"meta-nav\">\u2190<\/span> 15-Touch_STMPE811-Library (STM32F429)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=317\" title=\"17-SPI_HD-TM1638-Library (STM32F429)\">17-SPI_HD-TM1638-Library (STM32F429) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>diese Library dient zum benutzen der SPI-Schnittstelle im Master-Mode<br \/>\n(im Half-Duplex Betrieb)<\/p>\n<p>in diesem Mode wird nur eine Datenleitung ben\u00f6tig (DIO) statt MOSI und MISO<\/p>\n<p>die SPI-Pins die benutzt werden sollen, m\u00fcssen im C-File eingetragen werden<br \/>\n(im H-File kann der Clock-Vorteiler gew\u00e4hlt werden)<\/p>\n<p>die Library kann als LoLevel-Funktion nur die Schnittstelle (in einem der 8 SPI-Modes) initialisieren und ein Byte per SPI senden\/empfangen. Das setzen der ChipSelect-Leitung muss von der \u00dcbergeordneten Funktion gemacht werden<\/p>\n<p>es gibt 6 identische Librarys, getrennt f\u00fcr SPI1 bis SPI6<\/p>\n<p>im Beispiel wurde SPI4 benutzt mit dieser Pinbelegung :<\/p>\n<pre lang=\"c\" line=\"1\">SCK an PE2\r\nDIO an PE6<\/pre>\n<p><strong>Enumerationen (f\u00fcr SPI1) :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef 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}SPI1_Mode_t;<\/pre>\n<p><strong>:<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef enum {\r\n  SPI_FIRST_BYTE = 0,  \/\/ erstes Byte (von mehreren)\r\n  SPI_LAST_BYTE,       \/\/ letztes Byte (von mehreren)\r\n  SPI_OTHER_BYTE,      \/\/ nicht erstes und nicht letztes Byte\r\n  SPI_SINGLE_BYTE      \/\/ ein einzelnes Byte\r\n}SPI1_Byte_t;<\/pre>\n<p><strong>Funktionen (f\u00fcr SPI1) :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">ErrorStatus UB_SPI1_HD_Init(SPI1_Mode_t mode);       \/\/ zum initialisieren der SPI-Schnittstelle\r\nvoid UB_SPI1_HD_SendByte(uint8_t wert);              \/\/ zum senden eines Bytes\r\nuint8_t UB_SPI1_HD_ReceiveByte(SPI1_Byte_t byte_nr); \/\/ zum empfangen eines Bytes<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 05.11.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      : STM32F429\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 SPI-LoLevel-Library (Half-Duplex)\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\/\/ In Configuration diese Define hinzuf\u00fcgen :\r\n\/\/ \"STM32F429_439xx\" , \"__ASSEMBLY__\" , \"USE_STDPERIPH_DRIVER\"\r\n\/\/--------------------------------------------------------------\r\n\r\n#include \"main.h\"\r\n#include \"stm32_ub_spi4_hd.h\"\r\n\r\n\/\/--------------------------------------------------------------\r\n\/\/ ein Byte per SPI (Half-Duplex) senden\r\n\/\/--------------------------------------------------------------\r\nvoid spi_send(uint8_t wert)\r\n{\r\n  \/\/ hier Code einf\u00fcgen und\r\n  \/\/ ChipSelect-Pin auf LO legen\r\n\r\n  \/\/ byte senden\r\n  UB_SPI4_HD_SendByte(wert);\r\n\r\n  \/\/ hier Code einf\u00fcgen und\r\n  \/\/ ChipSelect-Pin auf HI legen\r\n}\r\n\r\n\/\/--------------------------------------------------------------\r\n\/\/ ein Byte per SPI (Half-Duplex) empfangen\r\n\/\/--------------------------------------------------------------\r\nuint8_t spi_receive(void)\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  \/\/ ein einzelnes byte empfangen\r\n  ret_wert=UB_SPI4_HD_ReceiveByte(SPI_SINGLE_BYTE);\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  SystemInit(); \/\/ Quarz Einstellungen aktivieren\r\n\r\n  \/\/ SPI4 (Half-Duplex) initialisieren\r\n  \/\/ im Mode0 mit MSB-First\r\n  UB_SPI4_HD_Init(SPI_MODE_0_MSB);\r\n\r\n  \/\/ den Wert 0x45 per SPI (Half-Duplex) senden\r\n  spi_send(0x45);\r\n\r\n  \/\/ einen Wert per SPI (Half-Duplex) empfangen\r\n  wert=spi_receive();\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=\"wp-content\/uploads\/2013\/11\/spi_HalfDuplex_f429_v100.zip\">spi_HalfDuplex_f429_v100<\/a><\/p>\n<p>Hier der komplette CooCox-Projektordner zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"wp-content\/uploads\/2013\/11\/Demo_F429_16.zip\">Demo_F429_16<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>diese Library dient zum benutzen der SPI-Schnittstelle im Master-Mode (im Half-Duplex Betrieb) in diesem Mode wird nur eine Datenleitung ben\u00f6tig (DIO) statt MOSI und MISO die SPI-Pins die benutzt werden sollen, m\u00fcssen im C-File eingetragen werden (im H-File kann der &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=315\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"parent":160,"menu_order":16,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[129],"tags":[214,9,49,102],"class_list":["post-315","page","type-page","status-publish","hentry","category-stm32f429","tag-half-duplex","tag-library","tag-spi","tag-stm32f429"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/315","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/315\/revisions"}],"predecessor-version":[{"id":1678,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/315\/revisions\/1678"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/160"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}