cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use i2c to communicate two STM32F103

kadir ustun1
Senior

I want to i2c to communicate two STM32F103. one of them will be a slave and other will be master. But program is stop on this :

void SendI2CByteData (I2C_TypeDef* I2Cx, uint8_t SlaveAddr, uint8_t Data)

{

 __IO uint8_t temp = 0;

 I2C_GenerateSTART(I2Cx, ENABLE);                                           /* NOTE: Generate Start Condition*/

 while ((I2Cx->SR1&0x0001) != 0x0001);

 I2C_Send7bitAddress(I2Cx, SlaveAddr<<1, I2C_Direction_Transmitter);                          /* NOTE: Send Slave Addres. Slave addr'yi 1 sola kaydiriyorum ki write biti yazilsin*/

 while ((I2Cx->SR1 &0x0002) != 0x0002);                                        /* NOTE: Wait Data to transgfer*/

 temp = I2Cx->SR2;

 while(!I2C_GetFlagStatus(I2C2,I2C_FLAG_TXE))

 I2C_SendData(I2Cx, Data);                                               /* NOTE: Sending Data */

 while ((I2Cx->SR1 & 0x00004) != 0x000004);                                      /* NOTE: Wait data sending */

 I2C_GenerateSTOP(I2Cx, ENABLE);                                            /* NOTE: Is All Data transfering, then generate stop otherwise i2c bus is hang*/

 while ((I2Cx->CR1&0x200) == 0x200);

}

program stop this line :

 while ((I2Cx->SR1 & 0x00004) != 0x000004);                                      /* NOTE: Wait data sending

Please can you help me ?

13 REPLIES 13
kadir ustun1
Senior

Actually Slave device recived a data, but did not receive second data. master device was stop at second data. I don't know couse

Again, have you got your Master thoroughly tested and debugged working with a standard slave?

If you haven't, then you need to do that first!

If you have, then you should be familiar with what happens when it is working properly - and, from that, be able to see where it's going wrong with your slave...

Yes ı did. ​İt is working properly. İt has no problem. But now it has a problem that ı dont know

Then you need to get debugging ...