2018-01-19 01:29 AM
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 ???
2018-01-19 02:07 AM
Hi
doumandjisamah
,I recommend you to have a look to I2C examples under the STM32F1 cube firmware package:
-Nesrine-
2018-01-19 03:24 AM
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
2018-01-19 04:27 AM
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