{"id":483,"date":"2017-11-24T23:54:29","date_gmt":"2017-11-24T22:54:29","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=483"},"modified":"2017-12-30T19:39:19","modified_gmt":"2017-12-30T18:39:19","slug":"74-spi_slave-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=483","title":{"rendered":"74-SPI_Slave-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=481\" title=\"73-FreeRTOS-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 73-FreeRTOS-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=485\" title=\"75-String-Library (STM32F4)\">75-String-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit dieser Library kann der STM32F4 als SPI-Slave eingesetzt werden.<\/p>\n<p>Der Slave simuliert ein 256-Byte gro\u00dfes SPI-RAM. Die SPI-Funktionen laufen per Interrupt ab. Es gibt zwei Funktionen f\u00fcr read\/write vom internen RAM.<\/p>\n<p>Ein SPI-Master kann \u00fcber Kommandos ein Byte in das interne RAM vom Slave speichern, ein Byte aus dem RAM vom Slave auslesen oder eine ID-Nummer vom Slave abfragen.<br \/>\n(Der SPI-Mode vom Master und Slave muss dabei gleich sein !!)<\/p>\n<p>Die 3 Kommdos die implementiert sind, sind alle 3 Bytes lang :<\/p>\n<pre lang=\"c\" line=\"1\">CMD-01 = Read ID\r\nMaster : 0x01 ,Dummy,Dummy\r\nSlave  : Dummy,0x32 ,0x07\r\n\r\nCMD-02 = Write Byte\r\nMaster : 0x02 ,Adr  ,Value\r\nSlave  : Dummy,Dummy,Dummy\r\n\r\nCMD-03 = Read Byte\r\nMaster : 0x03 ,Adr  ,Dummy\r\nSlace  : Dummy,Dummy,Value<\/pre>\n<p>Im Beispiel wartet der Slave solange, bis ein Master per SPI in die RAM-Adresse 0\u00d700 den Wert 0\u00d712 geschrieben hat, dann wird die gr\u00fcne LED eingeschaltet.<\/p>\n<p>die SPI-Pins die benutzt werden sollen, m\u00fcssen im C-File eingetragen werden<br \/>\n(im H-File kann die Gr\u00f6\u00dfe vom RAM eingestellt werden)<\/p>\n<p>es gibt 3 identische Librarys, getrennt f\u00fcr SPI1, SPI2 und SPI3<\/p>\n<p>im Beispiel wurde SPI2 benutzt mit dieser Pinbelegung :<\/p>\n<pre lang=\"c\" line=\"1\">SCK an PB13\r\nMOSI an PB15\r\nMISO an PC14\r\nSlaveSelect an PB12<\/pre>\n<p><strong>Voraussetzungen :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : GPIO, SPI, MISC\r\nBenutzte Librarys : keine<\/pre>\n<p><strong>Enumeration :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">typedef enum {\r\n  SPI_SMODE_0_MSB = 0,  \/\/ CPOL=0, CPHA=0 (MSB-First)\r\n  SPI_SMODE_1_MSB,      \/\/ CPOL=0, CPHA=1 (MSB-First)\r\n  SPI_SMODE_2_MSB,      \/\/ CPOL=1, CPHA=0 (MSB-First)\r\n  SPI_SMODE_3_MSB,      \/\/ CPOL=1, CPHA=1 (MSB-First)\r\n  SPI_SMODE_0_LSB,      \/\/ CPOL=0, CPHA=0 (LSB-First)\r\n  SPI_SMODE_1_LSB,      \/\/ CPOL=0, CPHA=1 (LSB-First)\r\n  SPI_SMODE_2_LSB,      \/\/ CPOL=1, CPHA=0 (LSB-First)\r\n  SPI_SMODE_3_LSB       \/\/ CPOL=1, CPHA=1 (LSB-First)\r\n}SPI2_SMode_t;<\/pre>\n<p><strong>Funktionen (f\u00fcr SPI2) :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">ErrorStatus UB_SPI2_Slave_Init(SPI2_SMode_t mode);       \/\/ zum init als SPI-Slave\r\nuint8_t UB_SPI2_Slave_ReadByte(uint8_t adr);             \/\/ zum lesen vom RAM\r\nvoid UB_SPI2_Slave_WriteByte(uint8_t adr, uint8_t wert); \/\/ zum schreiben in das RAM<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 01.02.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 SPI-Slave-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_led.h\"\r\n#include \"stm32_ub_spi2_slave.h\"\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  \/\/ init der LEDs\r\n  UB_Led_Init();\r\n\r\n  \/\/ init vom SPI-2 im Slave-Mode\r\n  UB_SPI2_Slave_Init(SPI_SMODE_0_MSB);\r\n\r\n  while(1)\r\n  {\r\n    \/\/ Wert vom RAM an Adresse 0x00 auslesen\r\n    wert=UB_SPI2_Slave_ReadByte(0x00);\r\n\r\n    \/\/ LEDs je nach Inhalt schalten\r\n    if(wert==0x12) {\r\n      UB_Led_On(LED_GREEN);\r\n      UB_Led_Off(LED_RED);\r\n    }\r\n    else {\r\n      UB_Led_On(LED_RED);\r\n      UB_Led_Off(LED_GREEN);\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\/02\/ub_stm32f4_spi_slave_v100.zip\">ub_stm32f4_spi_slave_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\/02\/Demo_74_SPI_Slave.zip\">Demo_74_SPI_Slave<\/a><\/p>\n<hr \/>\n<h3 id=\"comments-title\">8 Antworten auf <em>74-SPI_Slave-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-2352\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-2352\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/f77352d50cd91015096c6f5f953dd637?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\">sakarin<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">17. Oktober 2014 um 03:25<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Thank you very much for sharing this,<br \/>\nI downloaded your example and modified to my stm32f3discovery board and it works. I have question about the NSS pin that I guess it is a CS pin but the NSS pin is disconnected, the SPI2_IRQHandler() still interrupt so, I worry when connect my board to another spi devices, it will has error. Please share how to make the NSS pin as a real CS pin.<\/p>\n<p>Thanks in advance.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-2354\" class=\"comment odd alt thread-odd thread-alt depth-1\">\n<div id=\"comment-2354\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/f77352d50cd91015096c6f5f953dd637?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\">sakarin<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">17. Oktober 2014 um 04:45<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>I sent you an email in the morning, Now I have changed<\/p>\n<p>GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;<\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Code \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<\/p>\n<p>\/\/ SPI als Alternative-Function mit PullDown<br \/>\nGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;<br \/>\nGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br \/>\nGPIO_InitStructure.GPIO_OType = GPIO_OType_PP;<br \/>\n\/\/GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;<br \/>\nGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;<\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<\/p>\n<p>and it seems to be working, the spi slave can send data when the NSS (CS) is LOW.<br \/>\nJust asking you is it correct?<\/p>\n<p>Best regards,<br \/>\nSakarin<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2359\" class=\"comment byuser comment-author-admin_ub bypostauthor even depth-2\">\n<div id=\"comment-2359\">\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. Oktober 2014 um 21:05<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hi Sakarin,<br \/>\nIf you have only one slave than your modification is ok.<br \/>\nBut if you have more than one spi-slave on this bus you have to connect<br \/>\nthe SlaveSelect-Pin (PB12 in this demo) with the master !<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-2658\" class=\"comment odd alt thread-even depth-1\">\n<div id=\"comment-2658\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/f77352d50cd91015096c6f5f953dd637?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\">sakarin<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">8. Dezember 2014 um 11:24<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hi,<\/p>\n<p>Thanks again for your answer.<br \/>\nNow, I am trying to move the code to use DMA but it does not work. Could you share about the modification to use DMA?<\/p>\n<p>Best regards,<br \/>\nSakarin<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2661\" class=\"comment byuser comment-author-admin_ub bypostauthor even depth-2\">\n<div id=\"comment-2661\">\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\">8. Dezember 2014 um 21:12<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>i dont have a spi-dma demo. but ST has one \u201cSTM32F4xx_StdPeriph_Examples\\SPI\\SPI_TwoBoards\\SPI_DataExchangeDMA\u201d<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-2768\" class=\"comment odd alt thread-odd thread-alt depth-1\">\n<div id=\"comment-2768\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/f77352d50cd91015096c6f5f953dd637?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\">sakarin<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">24. Dezember 2014 um 10:11<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Thank you very much your suggestion. I tried to understand it but it gets data on the main program. Do you have some examples to work on SPI2 with DMA interrupt?<\/p>\n<p>\/\/ SPI2_RX \/\/<br \/>\nvoid DMA1_Channel4_IRQHandler(void)<br \/>\n{<\/p>\n<p>}<\/p>\n<p>\/\/SPI2_TX \/\/<br \/>\nvoid DMA1_Channel5_IRQHandler(void)<br \/>\n{<\/p>\n<p>}<\/p>\n<p>I wrote my code and it can enter to interrupts above when receive spi message but don\u2019t know how to read the receiving data from spi in debug mode of CooCox.<\/p>\n<p>void SPI_Slave_and_DMA_Configuration(void)<br \/>\n{<br \/>\nGPIO_InitTypeDef GPIO_InitStructure;<br \/>\nSPI_InitTypeDef SPI_InitStructure; \/\/Variable used to setup the SPI<br \/>\nDMA_InitTypeDef DMA_InitStructure; \/\/Variable used to setup the DMA<\/p>\n<p>\/\/ SPI-Clock enable<br \/>\nRCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);<\/p>\n<p>\/\/ Clock Enable der Pins, GPIOB<br \/>\nRCC_AHBPeriphClockCmd(SPI2DEV.SCK.CLK, ENABLE);<br \/>\nRCC_AHBPeriphClockCmd(SPI2DEV.MOSI.CLK, ENABLE);<br \/>\nRCC_AHBPeriphClockCmd(SPI2DEV.MISO.CLK, ENABLE);<br \/>\nRCC_AHBPeriphClockCmd(SPI2DEV.NSS.CLK, ENABLE);<\/p>\n<p>\/\/ SPI Alternative-Functions mit den IO-Pins verbinden<br \/>\nGPIO_PinAFConfig(SPI2DEV.SCK.PORT, SPI2DEV.SCK.SOURCE, GPIO_AF_5);<br \/>\nGPIO_PinAFConfig(SPI2DEV.MOSI.PORT, SPI2DEV.MOSI.SOURCE, GPIO_AF_5);<br \/>\nGPIO_PinAFConfig(SPI2DEV.MISO.PORT, SPI2DEV.MISO.SOURCE, GPIO_AF_5);<br \/>\nGPIO_PinAFConfig(SPI2DEV.NSS.PORT, SPI2DEV.NSS.SOURCE, GPIO_AF_5);<\/p>\n<p>\/\/ SPI als Alternative-Function mit PullDown<br \/>\nGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;<br \/>\nGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br \/>\nGPIO_InitStructure.GPIO_OType = GPIO_OType_PP;<br \/>\n\/\/GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;<br \/>\nGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; \/\/ ok<\/p>\n<p>\/\/ SCK-Pin<br \/>\nGPIO_InitStructure.GPIO_Pin = SPI2DEV.SCK.PIN;<br \/>\nGPIO_Init(SPI2DEV.SCK.PORT, &amp;GPIO_InitStructure);<br \/>\n\/\/ MOSI-Pin<br \/>\nGPIO_InitStructure.GPIO_Pin = SPI2DEV.MOSI.PIN;<br \/>\nGPIO_Init(SPI2DEV.MOSI.PORT, &amp;GPIO_InitStructure);<br \/>\n\/\/ MISO-Pin<br \/>\nGPIO_InitStructure.GPIO_Pin = SPI2DEV.MISO.PIN;<br \/>\nGPIO_Init(SPI2DEV.MISO.PORT, &amp;GPIO_InitStructure);<br \/>\n\/\/ NSS-Pin<br \/>\nGPIO_InitStructure.GPIO_Pin = SPI2DEV.NSS.PIN;<br \/>\nGPIO_Init(SPI2DEV.NSS.PORT, &amp;GPIO_InitStructure);<\/p>\n<p>\/\/ Reset SPI Interface<br \/>\nSPI_I2S_DeInit(SPI2);<\/p>\n<p>\/\/== SPI2 configuration<br \/>\nSPI_StructInit(&amp;SPI_InitStructure);<br \/>\nSPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;<br \/>\nSPI_InitStructure.SPI_Mode = SPI_Mode_Slave;<br \/>\nSPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;<br \/>\nSPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;<br \/>\nSPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;<br \/>\nSPI_InitStructure.SPI_NSS = SPI_NSS_Hard;<br \/>\nSPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;<br \/>\nSPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;<br \/>\nSPI_InitStructure.SPI_CRCPolynomial = 7;<br \/>\nSPI_Init(SPI2, &amp;SPI_InitStructure);<\/p>\n<p>\/\/\u2013Enable DMA1 clock\u2013<br \/>\nRCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);<\/p>\n<p>\/\/==Configure DMA1 \u2013 Channel4== (SPI -&gt; memory)<br \/>\nDMA_DeInit(DMA1_Channel4); \/\/Set DMA registers to default values<br \/>\nDMA_StructInit(&amp;DMA_InitStructure);<br \/>\nDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&amp;SPI2-&gt;DR; \/\/Address of peripheral the DMA must map to<br \/>\nDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&amp;SPIReceivedValue[0]; \/\/Variable to which received data will be stored<br \/>\nDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;<br \/>\nDMA_InitStructure.DMA_BufferSize = 1; \/\/Buffer size<br \/>\n\/\/ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;<br \/>\nDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;<br \/>\nDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;<br \/>\n\/\/ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;<br \/>\n\/\/ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;<br \/>\nDMA_InitStructure.DMA_Mode = DMA_Mode_Circular;<br \/>\nDMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;<br \/>\nDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;<br \/>\n\/\/ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;<br \/>\nDMA_InitStructure.DMA_Priority = DMA_Priority_High;<br \/>\nDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;<br \/>\nDMA_Init(DMA1_Channel4, &amp;DMA_InitStructure); \/\/Initialise the DMA<br \/>\nDMA_Cmd(DMA1_Channel4, ENABLE); \/\/Enable the DMA1 \u2013 Channel4<\/p>\n<p>\/\/==Configure DMA1 \u2013 Channel5== (memory -&gt; SPI)<br \/>\nDMA_DeInit(DMA1_Channel5); \/\/Set DMA registers to default values<br \/>\nDMA_StructInit(&amp;DMA_InitStructure);<br \/>\nDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&amp;SPI2-&gt;DR; \/\/Address of peripheral the DMA must map to<br \/>\nDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&amp;SPITransmittedValue[0]; \/\/Variable from which data will be transmitted<br \/>\nDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;<br \/>\nDMA_InitStructure.DMA_BufferSize = 1; \/\/Buffer size<br \/>\n\/\/ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;<br \/>\nDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;<br \/>\nDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;<br \/>\n\/\/ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;<br \/>\n\/\/ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;<br \/>\nDMA_InitStructure.DMA_Mode = DMA_Mode_Circular;<br \/>\nDMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;<br \/>\nDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;<br \/>\n\/\/ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;<br \/>\nDMA_InitStructure.DMA_Priority = DMA_Priority_High;<br \/>\nDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;<br \/>\nDMA_Init(DMA1_Channel5, &amp;DMA_InitStructure); \/\/Initialise the DMA<br \/>\nDMA_Cmd(DMA1_Channel5, ENABLE); \/\/Enable the DMA1 \u2013 Channel5<\/p>\n<p>\/\/ Enable SPI2<br \/>\nSPI_Cmd(SPI2, ENABLE);<\/p>\n<p>\/\/ Enable the SPI2 RX &amp; TX DMA requests<br \/>\nSPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx | SPI_I2S_DMAReq_Tx, ENABLE);<br \/>\n}<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2777\" class=\"comment byuser comment-author-admin_ub bypostauthor even depth-2\">\n<div id=\"comment-2777\">\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\">31. Dezember 2014 um 14:53<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>if you need SPI-Master with DMA you can try this new Library :<br \/>\n<a href=\"indexebfd.html?page_id=4593\" rel=\"nofollow\">http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=4593<\/a><\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<li id=\"li-comment-2788\" class=\"comment odd alt thread-even depth-1\">\n<div id=\"comment-2788\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/f77352d50cd91015096c6f5f953dd637?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\">sakarin<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">8. Januar 2015 um 05:08<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Thank you! now I have fixed the code and it is working as I wish.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Mit dieser Library kann der STM32F4 als SPI-Slave eingesetzt werden. Der Slave simuliert ein 256-Byte gro\u00dfes SPI-RAM. Die SPI-Funktionen laufen per Interrupt ab. Es gibt zwei Funktionen f\u00fcr read\/write vom internen RAM. Ein SPI-Master kann \u00fcber Kommandos ein Byte in &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=483\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":74,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[9,230,49,7],"class_list":["post-483","page","type-page","status-publish","hentry","category-stm32f4","tag-library","tag-slave","tag-spi","tag-stm32f4"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/483","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=483"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/483\/revisions"}],"predecessor-version":[{"id":1613,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/483\/revisions\/1613"}],"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=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}