Home | Projects | Notes > MCU Peripheral Drivers > I2C Application 3: Master Rx (Interrupt) (i2c_03_master_rx_interrupt.c)

I2C Application 3: Master Rx (Interrupt) (i2c_03_master_rx_interrupt.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

 

i2c-application-communication-2-interfaces

 

STM32 Board and Arduino Board Voltage Levels

 

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

Procedure to Read Data from Slave (Arduino)

  1. Master sends command code 0x51 to read the 1 byte of length information from the slave.

  2. Master sends command code 0x52 to read the complete data from the slave. (Reading byte-by-byte based on the length information fetched in Step 1)

  3. (Master displays the received data using semihosting.)

Using printf() to Print Messages in STM32CubeIDE Console

 

Setup

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

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

 

i2c-application-2-hardware-setup

 

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

 

Code

i2c_03_master_rx_interrupt.c

Path: Project/Src/

To test ACK failure error, simply try and modify the master's address to 0x66, compile and run the program. See if the error message appears in the console.

 

Arduino Sketch (002I2CSlaveTxString.ino)

 

Testing

The following snapshots are taken using the Logic Analyzer.

 

Entire Communication

 

i2c-application-3-testing-entire-communication

 

Cross-Checking using the STM32CubeIDE Console

 

i2c-application-3-testing-stm32cubeide