Home | Projects | Notes > MCU Peripheral Drivers > I2C Application 4: Slave Tx (Interrupt) (i2c_04_slave_tx_interrupt.c)

I2C Application 4: Slave Tx (Interrupt) (i2c_04_slave_tx_interrupt.c)

 

Requirements

External Pull-Up Resistance Calculation

Rp(max)=tr(max)0.8473×Cb=1000×1090.8473×400×10123k
tr(max)0.8×Rp×Cb

Parts Needed

  1. Arduino board

  2. STM32 board

  3. Logic level converter

  4. Breadboard and jumper wires

  5. 2 pull-up resistors of resistance 3.3 kΩ or 4.7 kΩ (You can also use internal pull-up resistors of the pins in place of external resistors.)

    Q: We calculated the Rp(max) to be 3 kΩ. If 3 is the max, then why would 3.3 or 4.7 kΩ resistors work? Wouldn't these be higher resistance than the max? Is there a tolerable range? If so, how do I find this range?

    A: Rp(max) refers to the maximum recommended value for the pull-up resistor. If the calculated Rp(max) is 3kOhms, it means that the manufacturer or standard recommends using a pull-up resistor with a value equal to or lower than 3kOhms for reliable operation.

    However, using a resistor with a slightly higher value, such as 3.3kOhms or 4.7kOhms, is generally acceptable in practice. The bus capacitance and other factors in the system design can influence the actual pull-up resistor value that works reliably. As long as the chosen resistor value is close to the recommended range and the overall system performance is satisfactory, using 3.3kOhms or 4.7kOhms resistors should be fine.

    It's important to note that selecting a pull-up resistor with a significantly higher value than Rp(max) may lead to slower rise times and increased susceptibility to noise or signal integrity issues. On the other hand, choosing a resistor with a significantly lower value may result in excessive current flow and power dissipation. Therefore, it's generally best to stay within the recommended range while considering the specific requirements and constraints of the system.

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 Send Data to Master (Arduino) as Slave (STM32)

Master (Arduino) will control the I2C transaction. Slave (STM32) will simply react to master's commands.

  1. Master sends command code (0x51) to fetch 1 byte of data length information from the slave.

  2. Master sends command code (0x52) to read the complete data from the slave.

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

 

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

 

Code

i2c_04_slave_tx_interrupt.c

Path: Project/Src/

 

Arduino Sketch (003I2CMasterRxString.ino)

 

Testing

The following snapshots are taken using the Logic Analyzer.

 

Entire Communication

 

i2c-application-4-testing-entire-communication

 

Communication in Detail

 

i2c-application-4-testing-communication-part-1

 

i2c-application-4-testing-communication-part-2

 

Cross-Checking using the Arduino IDE Serial Monitor Tool

 

i2c-application-4-testing-arduino-ide