Home | Projects | Notes > MCU Peripheral Drivers > SPI Application 2: Master Tx (Blocking) (spi_02_master_tx_blocking.c)

SPI Application 2: Master Tx (Blocking) (spi_02_master_tx_blocking.c)

 

Requirements

Parts Needed

  1. Arduino board

  2. STM32 board

  3. Logic level converter

  4. Breadboard and jumper wires

STM32 Board and Arduino Board Communication Interfaces

 

spi-application-2-communication-interfaces

 

STM32 Board and Arduino Board Voltage Levels

 

spi-application-2-stm32-arduino-voltage-levels

 

 

Setup

1. Find out the GPIO pins that can be used for SPI2 communication

2. Connect STM32 Discovery board with Arduino Uno board SPI pins

 

spi-application-2-hardware-setup

 

3. Power Arduino board and upload SPI slave sketch to Arduino

 

Code

spi_02_master_tx_blocking.c

Path: Project/Src/

The master's clock frequency has been adjusted from 2 MHz (prescalar = 8) to 500 KHz (prescalar = 32) to be compatible with the baudrate (1200) of the slave.

 

Arduino Sketch (001SPISlaveRxString.ino)

Original baudrate (9600) has been changed to 1200 since the communication didn't work with the original baudrate. (In the STM32 application, the master's clock frequency has been adjusted from 2 MHz to 500 KHz accordingly.)

 

Testing

The following snapshots are taken using the Logic Analyzer.

 

Entire Communication

spi-application-2-testing-entire-communication

Notice that as soon as SPE is set to 0, NSS is pulled to GND (LOW), and as soon as SPE is set to 1, NSS is pulled to HIGH automatically by the hardware.

 

Arduino IDE Serial Monitor

spi-application-2-testing-arduino-ide