Home | Projects | Notes > MCU Peripheral Drivers > SPI Application 3: Master-Slave Tx Rx (Blocking) (spi_03_master_tx_rx_blocking.c)

SPI Application 3: Master Tx Rx (Blocking) (spi_03_master_tx_rx_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-3-communication-interfaces

 

STM32 Board and Arduino Board Voltage Levels

 

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

 

Master - Slave Communication

Application Flow Chart

 

sspi-application-3-flow-chart

 

Using printf() to Print Messages in STM32CubeIDE Console

 

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-3-hardware-setup

 

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

 

Code

spi_03_master_tx_rx_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 (002SPISlaveCmdHandling.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

디버깅 필요! 디버거 모드로 한 줄 한 줄 실행 시 양쪽 콘솔에서 메시지들 정상 출력. 그냥 run 시 ackByte에 slave의 ACK 값이 정상적으로 저장되지 않아 일부 항목 건너 뛰는 문제가 있음.