{"id":3833,"date":"2025-10-07T12:02:31","date_gmt":"2025-10-07T12:02:31","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=3833"},"modified":"2025-10-07T12:02:33","modified_gmt":"2025-10-07T12:02:33","slug":"spi-based-sensor-emulation-part-1-introduction","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=3833","title":{"rendered":"SPI Based Sensor Emulation Part 1: Introduction"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-1024x683.png\" alt=\"\" class=\"wp-image-3834\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-1024x683.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-300x200.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-768x512.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-1150x767.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-750x500.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-400x267.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM-250x167.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/ChatGPT-Image-Oct-7-2025-at-11_11_54-AM.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In this guide, we demonstrate how to emulate an SPI-based sensor using two STM32 Nucleo-64 boards\u2014one configured as the SPI master and the other as an emulated SPI sensor. In\u00a0<strong>Part 1<\/strong>, we will discuss the importance of this setup and explain how to configure both the master and slave MCUs for reliable SPI communication.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Introduction.<\/li>\n\n\n\n<li>Hardware connection.<\/li>\n\n\n\n<li>Master configuration.<\/li>\n\n\n\n<li>Slave configuration.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Introduction:<\/h2>\n\n\n\n<p>In modern embedded systems, the Serial Peripheral Interface (SPI) is one of the most widely used communication protocols for connecting microcontrollers with peripheral devices such as sensors, memory chips, and displays. Its simplicity, high speed, and full-duplex communication make it an ideal choice for applications that require fast and reliable data transfer. However, when developing or testing firmware that depends on SPI-based sensors, engineers often encounter a common challenge: the actual sensor hardware might not be available during early development, or it may be impractical to use due to limited quantities, procurement delays, or environmental constraints. This situation can slow down the entire development process and hinder firmware validation.<\/p>\n\n\n\n<p>To overcome this challenge, an effective approach is to&nbsp;<strong>emulate an SPI-based sensor using another STM32 microcontroller<\/strong>. By configuring one STM32 board as an SPI slave that mimics a sensor\u2019s communication behavior, developers can create a controlled environment that allows them to fully test and debug their SPI master firmware without needing the physical sensor. This technique not only accelerates the development process but also provides a flexible platform for simulating a variety of sensor responses and behaviors, such as normal readings, fault conditions, or specific data sequences, enabling comprehensive validation before deployment.<\/p>\n\n\n\n<p>In this project, we will use&nbsp;<strong>two STM32 Nucleo-64 boards<\/strong>. One board will function as the&nbsp;<strong>SPI master<\/strong>, representing the main controller unit\u2014typically the microcontroller in a real embedded application that communicates with sensors or external peripherals. The second board will serve as the&nbsp;<strong>SPI slave<\/strong>, emulating the SPI sensor device. This configuration provides a complete setup for developers to experiment with SPI signaling, synchronization, and data integrity while having full control over both sides of the communication link.<\/p>\n\n\n\n<p>In&nbsp;<strong>Part 1<\/strong>, we will discuss in detail the&nbsp;<strong>importance of SPI emulation<\/strong>&nbsp;in embedded system development and testing. We will explain how emulating sensors can significantly reduce development time, minimize dependency on hardware availability, and allow firmware engineers to test their SPI drivers in isolation. This method also facilitates easier debugging since the emulated slave MCU can be programmed to provide deterministic and predictable responses, making it easier to trace and analyze the master\u2019s behavior under different conditions.<\/p>\n\n\n\n<p>We will then move on to the&nbsp;<strong>configuration of both the master and slave MCUs<\/strong>. This includes setting up the SPI peripheral on both sides\u2014defining the clock polarity (CPOL), clock phase (CPHA), data frame size, bit order (MSB or LSB first), and communication speed. Additionally, we will configure the necessary GPIO pins (SCK, MISO, MOSI, and NSS) to establish a proper physical connection between the two boards. Timing considerations, interrupt usage, and synchronization techniques will also be discussed to ensure stable and accurate data exchange between the master and the emulated sensor.<\/p>\n\n\n\n<p>By the end of this section, you will have a solid understanding of how to prepare and configure both STM32 Nucleo-64 boards for SPI communication. More importantly, you will appreciate the broader purpose of SPI sensor emulation\u2014how it enhances testing efficiency, enables early firmware development, and provides a versatile platform for experimenting with SPI transactions, all before the actual sensor hardware becomes available. This approach represents a practical, powerful, and educational technique that benefits both beginners and experienced embedded engineers alike.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Hardware Connection:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>The connection as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"549\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-1024x549.jpg\" alt=\"\" class=\"wp-image-3835\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-1024x549.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-300x161.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-768x412.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-1536x823.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-2048x1098.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-1150x616.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-750x402.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-400x214.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-29-06-250x134.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>SPI Pins<\/td><td>Master STM32<\/td><td>Slave STM32<\/td><\/tr><tr><td>SCK<\/td><td>PA5 <\/td><td>PA5<\/td><\/tr><tr><td>MISO<\/td><td>PA6<\/td><td>PA6<\/td><\/tr><tr><td>MOSI<\/td><td>PA7<\/td><td>PA7<\/td><\/tr><tr><td>SPI CS<\/td><td>PA0<\/td><td>PA0<\/td><\/tr><tr><td>&#8212;<\/td><td>GND<\/td><td>GND<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Master Configuration:<\/h2>\n\n\n\n<p>We start off by creating new project as follows:<\/p>\n\n\n\n<p>Open STM32CubeIDE after selecting the workspace and create new project as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"738\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-1024x738.jpg\" alt=\"\" class=\"wp-image-3836\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-1024x738.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-300x216.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-768x553.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-1536x1107.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-1150x829.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-750x540.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-400x288.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20-250x180.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-40-20.jpg 1760w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, select your MCU and click next as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"839\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-1024x839.jpg\" alt=\"\" class=\"wp-image-3837\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-1024x839.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-300x246.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-768x629.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-1536x1259.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-2048x1678.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-1150x942.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-750x615.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-400x328.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-42-11-250x205.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Give the project a name and click on finish as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"813\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-813x1024.jpg\" alt=\"\" class=\"wp-image-3838\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-813x1024.jpg 813w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-238x300.jpg 238w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-768x968.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-750x945.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-400x504.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41-250x315.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-43-41.jpg 984w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Once the project has been created, STM32CubeMX window will appear. <\/p>\n\n\n\n<p>From connectivity, Select SPI1 and enable it master full duplex mode as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"825\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-825x1024.jpg\" alt=\"\" class=\"wp-image-3839\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-825x1024.jpg 825w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-242x300.jpg 242w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-768x953.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-1238x1536.jpg 1238w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-1150x1427.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-750x931.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-400x496.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41-250x310.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-45-41.jpg 1578w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Keep the parameters as is.<\/p>\n\n\n\n<p>Next, set PA0 as GPIO Output and give it CS name as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"918\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-1024x918.jpg\" alt=\"\" class=\"wp-image-3840\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-1024x918.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-300x269.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-768x688.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-1150x1031.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-750x672.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-400x359.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32-250x224.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-49-32.jpg 1446w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next, head to system core, GPIO and set PA0 level to high as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-734x1024.jpg\" alt=\"\" class=\"wp-image-3841\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-734x1024.jpg 734w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-215x300.jpg 215w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-768x1071.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-1102x1536.jpg 1102w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-1469x2048.jpg 1469w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-1150x1603.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-750x1046.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-400x558.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21-250x349.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-50-21.jpg 1522w\" sizes=\"(max-width: 734px) 100vw, 734px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for Master Configuration. Save the project and the code shall be generated.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Slave Configuration:<\/h2>\n\n\n\n<p>Create a new project and give it a name as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"813\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-813x1024.jpg\" alt=\"\" class=\"wp-image-3842\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-813x1024.jpg 813w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-238x300.jpg 238w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-768x968.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-750x945.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-400x504.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47-250x315.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-53-47.jpg 984w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, from connectivity, select SPI and set it to Full Duplex Slave as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"918\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-918x1024.jpg\" alt=\"\" class=\"wp-image-3843\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-918x1024.jpg 918w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-269x300.jpg 269w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-768x857.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-1376x1536.jpg 1376w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-1150x1283.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-750x837.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-400x446.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46-250x279.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-55-46.jpg 1706w\" sizes=\"(max-width: 918px) 100vw, 918px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, enable SPI interrupts as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"830\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-1024x830.jpg\" alt=\"\" class=\"wp-image-3844\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-1024x830.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-300x243.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-768x622.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-1150x932.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-750x608.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-400x324.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54-250x203.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-56-54.jpg 1182w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, Set PA0 as EXTI0 interrupt and give it a name of CS as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"993\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-1024x993.jpg\" alt=\"\" class=\"wp-image-3845\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-1024x993.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-300x291.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-768x745.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-1150x1115.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-750x727.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-400x388.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50-250x242.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-57-50.jpg 1394w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, from System Core, NVIC enable EXTI0 line as follows:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-877x1024.jpg\" alt=\"\" class=\"wp-image-3846\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-877x1024.jpg 877w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-257x300.jpg 257w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-768x896.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-1316x1536.jpg 1316w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-1150x1342.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-750x875.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-400x467.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27-250x292.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/10\/2025-10-07_14-59-27.jpg 1698w\" sizes=\"(max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for slave configuration.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Save project and this will generate the code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In part 2, we shall configure master to transmit data and the slave will receive it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Stay tuned.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we demonstrate how to emulate an SPI-based sensor using two STM32 Nucleo-64 boards\u2014one configured as the SPI master and the other as an emulated SPI sensor. In\u00a0Part 1, we will discuss the importance of this setup and explain how to configure both the master and slave MCUs for reliable SPI communication. In [&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-3833","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\/3833"}],"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=3833"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3833\/revisions"}],"predecessor-version":[{"id":3847,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3833\/revisions\/3847"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}