0
\$\begingroup\$

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!

\$\endgroup\$
  • 2
    \$\begingroup\$ Why is your STM8 slave code generating starts & stops?!? That's the master's job. \$\endgroup\$ – brhans Feb 3 '16 at 19:17
2
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.