{"id":739,"date":"2022-01-31T15:09:36","date_gmt":"2022-01-31T15:09:36","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=739"},"modified":"2022-01-31T15:09:37","modified_gmt":"2022-01-31T15:09:37","slug":"working-with-stm32f7-and-spi-serial-peripheral-interface-send-a-byte","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=739","title":{"rendered":"Working with STM32F7 and SPI (Serial Peripheral Interface): Send a byte"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/community.nxp.com\/t5\/image\/serverpage\/image-id\/1775i2B1DEDD6CA621B46\/image-size\/large?v=v2&amp;px=999\" alt=\"pastedImage_0.png\" title=\"pastedImage_0.png\" \/><\/figure><\/div>\n\n\n\n<p>In this guide, we shall discuss what is SPI and how transmit single byte over SPI.<\/p>\n\n\n\n<p>In this guide, we will cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is SPI<\/li><li>SPI pin setup<\/li><li>SPI initialize<\/li><li>SPI transmite function<\/li><li>Result<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is SPI<\/h2>\n\n\n\n<p>SPI, which stands for Serial Peripheral Interface, is a standard with a very specific hardware interface. A connection is between a master and a slave, with the master typical being a processor, and the slave being a peripheral such as a sensor, flash memory device, or a modem chip.&nbsp;&nbsp; It can also be used for processor to processor communications, but in this case, an additional handshake signal is often used. There are normally four signals between a master and a slave, the first is a clock signal, and this signal is always driven by the master, regard which device is transmitting.&nbsp; The second line is a data line for data going from the master to the slave, and this is designated as the master output, slave input line, are MOSI for short. It connects the SPI data out connection on the master and to the SPI data in connection on the slave.<\/p>\n\n\n\n<p>The next conductor is for data in the opposite direction and is labelled as the master input slave output line, are MISO for short. The last conductor is slave select with the slave chip selecting input, and is active low.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/community.nxp.com\/t5\/image\/serverpage\/image-id\/1775i2B1DEDD6CA621B46\/image-size\/large?v=v2&amp;px=999\" alt=\"pastedImage_0.png\" title=\"pastedImage_0.png\" \/><\/figure><\/div>\n\n\n\n<p>If you have more than one slave, with the first being perhaps a sensor of some kind, the slave will be dedicated to slave 1. If you add a second sensor, the top 3 interface line will be shared, but it dedicates for slave\u2019s line will be required for the second device, and the same is true of course for each of additional slave device.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/community.nxp.com\/t5\/image\/serverpage\/image-id\/1823iA304AA7FB6E2C238\/image-size\/large?v=v2&amp;px=999\" alt=\"pastedImage_1.png\" title=\"pastedImage_1.png\" \/><\/figure><\/div>\n\n\n\n<p>Most processors have a maxim of 4 slave selected lines.&nbsp; The four lines could be used effectively as a multiplexed address lines to access more than 4 slaves. You cannot have more than one master on the bus,&nbsp;&nbsp; since the interface is not support coordination between two masters as to which one is controlling the bus.<\/p>\n\n\n\n<p>Transmissions are typically sent as a sequence of bytes, but without a formal protocol, there is nothing restricting communication being&nbsp;&nbsp; byte based. Typical by frame sizes, are in 8 to 32 bits range.&nbsp; Also note the bytes and packets are not acknowledged as they are in i2c, and you could have a master synching communicating with the slave but, you don\u2019t really know of your communications are being received OK. However, some slave devices will echo bytes sent to it, which provides an acknowledgement to the master.&nbsp; it is how the data lines are synchronized with a clock signal.<\/p>\n\n\n\n<p><strong>Clock Polarity and Phasing<\/strong><\/p>\n\n\n\n<p>There are four different modes available, one mode each combination clocking in a low state and high state, with a data being read in a rising edge or falling edge of the clock signal.&nbsp; For modes 0 and 1, the clock is low in idle, which is referred to&nbsp; as clock and 0,&nbsp; For modes 2 and 3 then the clock is in high state when idle, so it has&nbsp; polarity&nbsp; , one , For modes 0 and 2, the data will be sampled by the receiving device&nbsp; on the leading edge of a clock signal.&nbsp; Relative to the idle state, which is referred to a clock phase of zero. So for mode 0, this means the rising edge of the clock and for mode 2, means the following edge of the clock, the other two modes, use a clock phase 1 which means that trailing edge of clock as a returns to an&nbsp; idle state.&nbsp; And this translates to a following edge for mode 1 and the rising edge for mode 3.&nbsp; Mode 0 is the most commonly supported setting. If multiple slaves in the same bus, you may have to reconfigure the settings for the master to which modes when you want to communicate with a different slave.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/community.nxp.com\/t5\/image\/serverpage\/image-id\/1822i008127221D9DF901\/image-size\/large?v=v2&amp;px=999\" alt=\"pastedImage_2.png\" title=\"pastedImage_2.png\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">2. SPI pin setup:<\/h2>\n\n\n\n<p>First thing first, we need to locate the pins of SPI1 in STM32F411 Nucleo-64. We can find those information in the datasheet of our microcontrol.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-1024x731.png\" alt=\"\" class=\"wp-image-467\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-1024x731.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-300x214.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-768x548.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-1536x1096.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-2048x1462.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-1150x821.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-750x535.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-400x285.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/Screen-Shot-2021-09-30-at-8.06.55-AM-250x178.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>From the table above, we conclude that SPI has alternate function 5 and the following pins:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>Pin&nbsp;<\/td><td>SPI Function<\/td><\/tr><tr><td>PA5<\/td><td>SCK (Serial Clock)<\/td><\/tr><tr><td>PA6<\/td><td>MISO (Master In Slave Out)<\/td><\/tr><tr><td>PA7<\/td><td>MOSI (Master Out Slave In)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>After than we can start by enabling clock access to GPIOA as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">RCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN; \/\/enable clock for GPIOA<\/pre><\/div>\n\n\n\n<p>Then setting PA5, PA6 and PA7 as alternate function mode as following<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">GPIOA-&gt;MODER|=GPIO_MODER_MODE5_1|GPIO_MODER_MODE6_1|GPIO_MODER_MODE7_1; \/\/set PA5, PA6 and PA7 to alternate function mode<\/pre><\/div>\n\n\n\n<p>Then we can set which AF shall be used. From the table we find that, it is alternate function 5. Hence, the AF can be set at following<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">GPIOA-&gt;AFR[0]|=(0x05&lt;&lt;20)|(0x05&lt;&lt;24)|(0x05&lt;&lt;28);<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">3. SPI initialising:<\/h2>\n\n\n\n<p>We start off by locating which bus SPI is connected to. We can find this in the datasheet.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"635\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-1024x635.png\" alt=\"\" class=\"wp-image-740\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-1024x635.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-300x186.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-768x476.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-1536x952.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-1150x713.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-750x465.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-400x248.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM-250x155.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.55.03-PM.png 1990w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>So, from the block diagram, SPI1 is connected to APB2 bus. Hence we can enable clock access as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">RCC-&gt;APB2ENR|=RCC_APB2ENR_SPI1EN; \/\/enable clock access to SPI1<\/pre><\/div>\n\n\n\n<p>Now, we can start configure the SPI as following:<\/p>\n\n\n\n<p>We start by enabling software slave management as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">SPI1-&gt;CR1|=SPI_CR1_SSM|SPI_CR1_SSI; \/\/software slave management<\/pre><\/div>\n\n\n\n<p>Then we select the SPI in master mode as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">SPI1-&gt;CR1|=SPI_CR1_MSTR;\/\/ set SPI as master mode<\/pre><\/div>\n\n\n\n<p>Now, we need to set the SPI data width to 8-bit, and this can be achieved from CR2 as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">SPI1-&gt;CR2|=(0x07&lt;&lt;8);<\/pre><\/div>\n\n\n\n<p>And finally, we can enable the SPI peripheral:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">SPI1-&gt;CR1|=SPI_CR1_SPE; \/\/enable SPI peripheral <\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">4. SPI transmit function<\/h2>\n\n\n\n<p>we can transmit data as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void spi_write ( uint8_t c){\n\twhile(!(SPI1-&gt;SR&amp;SPI_SR_TXE)){;} \/\/ wait to transmision buffer to be emplty\n\t\t\n\t*(volatile uint8_t *)&amp;SPI1-&gt;DR=c;\n \t\twhile((SPI1-&gt;SR&amp;SPI_SR_BSY)){;}\n}\n<\/pre><\/div>\n\n\n\n<p>Note: we need to type cast the SPI1-&gt;DR register to be 8-bit length<\/p>\n\n\n\n<p>Hence, the code is as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stm32f7xx.h&quot;                  \/\/ Device header\n#include &quot;stdint.h&quot;\nvoid spi_init(void);\n\nvoid delay(int ms);\n\n\n\n\nvoid spi_write ( uint8_t c){\n\twhile(!(SPI1-&gt;SR&amp;SPI_SR_TXE)){;} \/\/ wait to transmision buffer to be emplty\n\t\t\n\t*(volatile uint8_t *)&amp;SPI1-&gt;DR=c;\n \t\twhile((SPI1-&gt;SR&amp;SPI_SR_BSY)){;}\n}\n\n\n\nint main(void){\n\t\n\nspi_init();\n\t\nwhile(1)\n{\n\n\nspi_write(0x41);\ndelay(100);\n}\n\n}\n\n\nvoid spi_init(void)\n\t\n{\nRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN; \/\/enable clock forn gpio a\nRCC-&gt;APB2ENR|=RCC_APB2ENR_SPI1EN; \/\/enable clock for spi1\n\/\/GPIOA-&gt;MODER=0;\nGPIOA-&gt;MODER|=GPIO_MODER_MODER5_1|GPIO_MODER_MODER6_1|GPIO_MODER_MODER7_1;\nGPIOA-&gt;AFR[0]|=(0x05&lt;&lt;20)|(0x05&lt;&lt;24)|(0x05&lt;&lt;28);\nSPI1-&gt;CR1=0;\nSPI1-&gt;CR1|=SPI_CR1_SSM|SPI_CR1_SSI|SPI_CR1_MSTR; \nSPI1-&gt;CR2|=(0x07&lt;&lt;8);\nSPI1-&gt;CR1|=SPI_CR1_SPE;\n\n\n}\n\n\nvoid delay(int ms)\n{\n\tSysTick-&gt;LOAD=16000-1;\n\tSysTick-&gt;VAL=0;\n\tSysTick-&gt;CTRL=0x5;\n\t\tfor (int i=0;i&lt;ms;i++)\n\t\t{\n\t\t\twhile(!(SysTick-&gt;CTRL &amp;0x10000)){}\n\t\t}\n\tSysTick-&gt;CTRL=0;\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Results:<\/h2>\n\n\n\n<p>Once you upload the code, and connect an logic analyzer, you should get this<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"256\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-1024x256.png\" alt=\"\" class=\"wp-image-741\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-1024x256.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-300x75.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-768x192.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-1536x384.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-2048x512.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-1150x288.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-750x188.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-400x100.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/01\/Screen-Shot-2022-01-31-at-5.50.05-PM-250x63.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall discuss what is SPI and how transmit single byte over SPI. In this guide, we will cover the following: What is SPI SPI pin setup SPI initialize SPI transmite function Result 1. What is SPI SPI, which stands for Serial Peripheral Interface, is a standard with a very specific hardware [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-739","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/739"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=739"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":742,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions\/742"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}