cancel
Showing results for 
Search instead for 
Did you mean: 

i2c slave or master ???two carts stm32

TARHAN SAMAH
Senior
Posted on January 19, 2018 at 10:29

hello i need to use i2c to exchange data between two stm32f103c8 , 

one sends datas the other blinks and in both sides sends and receive to each other , i use a simple exemple but in one side it works one is master transmitting then slave is receing byy interrupt 

exemple stm(cart1) master trnsmits to slave -------------------------------> stm (cart2) slave receive ITby interrupts 

but how to make boths sides 

stm(cart1)   transmit master receive slave or recieve master IT  ----->stm(cart1)transmit master or slave and recieve

                                                                                                    <-----slave or master 

i cannot make it fullduplex wit same lines data and clk: 

HAL_I2C_Slave_Receive_IT(&hi2c2,0,(uint8_t *)aRxBuffer,1);//ENABLE RECEIVE IC2 INTERRUPT 

data_master[0]=i;

void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)

{

if (hi2c->Instance == I2C2 )

 {

    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);//blink led if we received an interrupt byte from i2c line

   HAL_I2C_Slave_Receive_IT(&hi2c2,(uint8_t *)aRxBuffer,1);//ENABLE RECEIVE IC2 INTERRUPT

}

}

while(1)

{

  HAL_I2C_Master_Transmit(&hi2c2,0,data_master,1,50);

HAL_Delay(50);

}

it bugs and i dont have any result both sides or one side ,

can you advice me one device can only be master or slave or can switch from one to another ,,, just i need to know how to send and receieve same time ??? 

3 REPLIES 3
Nesrine M_O
Lead II
Posted on January 19, 2018 at 11:07

Hi

doumandjisamah

,

I recommend you to have a look to I2C examples under the STM32F1 cube firmware package:

  1. STM32Cube_FW_F1_V1.6.0\Projects\STM32F103RB-Nucleo\Examples\I2C
  2. STM32Cube_FW_F1_V1.6.0\Projects\STM32F103RB-Nucleo\Examples\I2C\I2C_TwoBoards_ComPolling:This example describes how to perform I2C data buffer transmission/reception betweentwo boards in Polling mode.

-Nesrine-

Posted on January 19, 2018 at 11:24

thank you Nesrine for your answer ,yes i checked these exemple especıally the IT MODE ONE 

for polling mode i can do it very well full duplex communication

but if i make receiving in interrupt mode it bugs both sides ,or sometimes works then stops 

Posted on January 19, 2018 at 12:27

i cheked the exemples again so the stm can be master or slave not both same time!! , we have to decide and it will be fix during all working 

stm(1) master transmit+ master rx _IT

STM(2) SLAVE transmit+ slave rx_IT 

i did this but no working both sides its like bugging can any one clear me about this point with simple interrupt exemple thank you i add error managing and wait the port to be ready 

while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)

{

}

while(HAL_I2C_GetError(&hi2c2) == HAL_I2C_ERROR_AF);  

i repeat it in while (1) 

before sending 

thank you