Electrical – Arduino and STM8 I2C Communication

arduinoi2cstm8

I want to I2C communication stm8s(slave) and arduino uno(master), but it does not work.

Arduino Uno(master) code:

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop() {
  Wire.beginTransmission(0x30); // transmit to device #0x30
  Wire.write(0x15);              // sends one byte
  Wire.endTransmission();    // stop transmitting

  delay(500);
}

STM8 Slave Code with peripheral library: main.c

CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

I2C_DeInit();
I2C_Init(100000, SLAVE_ADDRESS, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16);

char veri_bas[1];

while (1)
{

I2C_GenerateSTART(ENABLE);

/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_ACK_NEXT);

/* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);


uint8_t gelen = I2C_ReceiveData();
//uint8_t gelen = 0x15;
sprintf(veri_bas ,"%d" ,gelen);
sendstring(veri_bas);
}

STM8 – main.h:

#ifndef __MAIN_H
#define __MAIN_H

#define I2C_SPEED 100000
#define SLAVE_ADDRESS  0x30

#endif /* __MAIN_H */

Arduino sends data, i saw it on the ossiloscope. Pinout(SCL-SDA-GND) and I2C resistors are correct. Sendstring function is correct. But it does not work. Thank you!

Best Answer

Your slave should not generate START and STOP events. It must wait for and respond to them appropriately.