I2C communication between 2 STM32F103C8T6 does not work

Post here first, or if you can't find a relevant section!
Post Reply
eeaciu21048
Posts: 1
Joined: Sat Apr 27, 2024 3:26 am

I2C communication between 2 STM32F103C8T6 does not work

Post by eeaciu21048 »

I am trying to communicate I2C between 2 STM32F103C8T6 but it does not work
Master code:

Code: Select all

#include<Wire.h>
int z[16];
void setup()
{
  Serial.begin(9600);
  delay(50);
  Wire.begin();
  delay(50);
}


void loop()
{
  Wire1.requestFrom(0x09, 16);  //to receive 16-byte;
  delay(50);
  Serial.print("Slave data: ");
  for (int i = 0; i < 16; i++)
  {
    z[i] = Wire.read();
    delay(50);
    Serial.print(z[i], DEC);
  }
  Serial.println();
  delay(1000);
}
Slave code:

Code: Select all

#include<Wire.h>
const uint8_t a = 0x09;
int transferArray[16] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
bool flag1 = LOW;
void setup()
{
  Serial.begin(9600);
  delay(50);
  Wire.begin(a);
  delay(50);
  Wire.onRequest(sendEvent);
  delay(50);
}
void loop()
{
 
}

void sendEvent()
{
  for (int i = 0; i < 16; i ++ )
    {
      Wire.write((transferArray[i]));
      delay(50); //I2C is byte-oriened Bus
      //Wire.write(lowByte(transferArray[i]));
    }
}
The result is: -1-1-1-1-1-1-1-1

I also use 2 pull-up resistors 4.7k for both SCL and SDA lines.
This code works on 2 Arduino Uno but I can not understand why it does not work on STM32.
Can somebody help me, please. Thank you very much!
Post Reply

Return to “General discussion”