# Project Name：Spi_Slave_Demo

---
## Function description

This demo demonstrates the use of the SPI driver in both master and slave modes.
After initialization, the program performs a test by transmitting data and comparing the transmitted and received data. The program also toggles an LED every 500 iterations of the main loop. 

 **User case**
 <pre>
  1. Sequence_0 -- Job_0 --------- SPI_0(Master) -- Channel_0(EB) : AsyncTransmit mode
  2. Sequence_1 -- Job_1 --------- SPI_1(Slave)  -- Channel_1(EB) : AsyncTransmit mode
</pre>

<p style="text-align: center;"><strong>Note</strong></p>

- This demo needs shorting the the SPI interface. Determine the SPI pins on both the master and slave instance. Common names for these pins are MOSI (Master Out Slave In), MISO (Master In Slave Out), SCK (Serial Clock), and SS (Slave Select or Chip Select).

+ The macros "MASTER_BOARD," "SLAVE_BOARD," and "MASTER_SLAVE_ON_SINGLE_BOARD" are defined. These macros are used to control the behavior of the program based on the specific configuration.***
  - 1. MASTER_BOARD: This macro is defined as 0(default), indicating that the current board is not the master board. It is used to conditionally compile specific code blocks that are intended for the master board.
  - 2. SLAVE_BOARD: This macro is also defined as 0(default), indicating that the current board is not the slave board. Similar to the MASTER_BOARD macro, it is used to conditionally compile code blocks specific to the slave board.
  - 3. MASTER_SLAVE_ON_SINGLE_BOARD: This macro is defined as 1(default), indicating that the current board supports both master and slave functionalities on the same board. It is used to conditionally compile code blocks specific to this configuration.
  
---

## Setup

+ ***Step1***: Refer to the ***SPI HW connection diagram***, establish direct connections between the corresponding SPI pins of the master and the slave（The silkscreen on the PCB is incorrect; please connect according to the correct markings on the schematic）.
+ ***Step2***: Open the Spi_Slave_Demo.yct with the YCT tool, config the toolchain per your required(by default, the VS code + GCC are used)
+ ***Step3***：Generate the codes， you can change the configurations if needed(to adapt to your own HW design), if so, please ensure all the modifications are OK with no any errors exist before generating the code.
+ ***Step4***: Open the generated project with VS code/IAR/Keil IDE per your selected.
+ ***Step5***: Compile the project, power on the EVB and download it to the EVB via the available debugger, such as a J-Link debugger probe.
+ ***Step6***: At last, enjoy the demo example.

### SPI HW connection diagram
- Identify the SPI pins on both the master and slave devices, typically labeled as MOSI (Master Out Slave In), MISO (Master In Slave Out), SCK (Serial Clock), and SS (Slave Select).
- Connect the MOSI pin of the master device to the MOSI pin of the slave device.
- Connect the MISO pin of the master device to the MISO pin of the slave device.
- Connect the SCK pin of the master device to the SCK pin of the slave device.
- Connect the SS pin of the master device to the SS pin of the slave device.
- Ensure that the SPI interface connections are secure and properly seated.

**SPI0 Master**

|  Function  |  MCU Pin  | EVB pin header|  
| ---- | ------- | ------ |
|  MOSI  |  PTE02  |  H4_10  |
|  MISO  |  PTE01  |  H4_18  |
|  SCK   |  PTE00  |  H4_19  |
|  SS2   |  PTE06  |  H4_09  |

**SPI1 Slave**

|  Function  |  MCU Pin  | EVB pin header|  
| ---- | ------- | ------ |
|  MOSI  |  PTD02  |  H3_21  |
|  MISO  |  PTB15  |  H3_15  |
|  SCK   |  PTE09  |  H1_23  |
|  SS0   |  PTD03  |  H3_20  |

---

## Hardware requirement
+ **EVB**: YTM32B1MD1-EVB-Q100-Rev.A/B
+ **Debugger**: J-Link HW v9 or later with YUNTU `YTM32B1MD1` patch(support package) installed.

**Note**: Please check the version number at the bottom of the EVB. If it is `YTM32B1MD1-EVB-Q100-Rev.A/B`, please use the example projects ending with `_RevA` for `Icu_Demo`.
---

## Software requirement

+ **Config & Code Generation Tool**
  + **MCAL**: Yuntu Config Tool(YCT) v2.7.0 or later version
+ **Compiler Toolchain**
  + **GCC**: GNU GCC v10.3 or later version
  + **Keil/MDK**: ARM Keil/MDK v5.36 or later version(`armclang v6.18.2` is recommended to be used as the compiler)
  + **IAR**: IAR v9.50 or later version
  + **VS Code**: Microsoft Visual Studio Code IDE v1.76 or later version(C/C++ support, GNU toolchain, CMake v3.25, ninja, Cortex-Debug extensions installation required)
+ **Debugger driver**
    + **J-Link**: SEGGER J-Link v7.82 or later version, YUNTU `YTM32B1MD1` patch(support package) installation required.
    + **Ozone Debugger tool**: SEGGER Ozone v3.28 or later version.

    ***Note***: **YTM32B1MD1** patch install required which can be obtained via **YCT** or contact ***YUNTU sales/FAE team***.

---