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!

asked Feb 3, 2016 at 19:15
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Why is your STM8 slave code generating starts & stops?!? That's the master's job. \$\endgroup\$ Commented Feb 3, 2016 at 19:17

1 Answer 1

3
\$\begingroup\$

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

answered Feb 4, 2016 at 2:29
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.