cancel
Showing results for 
Search instead for 
Did you mean: 

cannot send a message from a slave to a master i2c stm32f103!!

TARHAN SAMAH
Senior
Posted on January 22, 2018 at 10:06

hello trying to send a message from an stm32 slave to another stm32 master no success i2c protocol ,

from master to slave no prblm i can do it very well ,

i cheked many times the repository interrupt exemples and did like them but no any changing, here what i did 

slave part :

if(HAL_GPIO_ReadPin(GPIOA, BUTTON_Pin)==1)//USER BUTTON PUSHED

{//BUTTON

printf('BUTTON');

while(HAL_GPIO_ReadPin(GPIOA, BUTTON_Pin)==1) //wait button to be released

if(HAL_I2C_Slave_Transmit(&hi2c2,data_master,1,50)==HAL_OK)//slaves answer to master

{

// printf('slave send to master succeed');

while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)

{

}

//

}

}//BUTTON

this function always fails, can you advice me plz

6 REPLIES 6
Andrew Neil
Evangelist
Posted on January 22, 2018 at 11:46

Slaves can't just send unsolicited messages to the Master - this is fundamental to the I2C protocol.

I2C Protocol Specification: 

https://www.nxp.com/docs/en/user-guide/UM10204.pdf

 

https://en.wikipedia.org/wiki/I%C2%B2C

 

https://learn.sparkfun.com/tutorials/i2c

 
TARHAN SAMAH
Senior
Posted on January 22, 2018 at 12:54

thank you very much mister Andrew so the exemple in the repository I2C_TwoBoards_ComIT I2C Two Boards Communication IT Example, is eacty what i need . 

for exemple i need to push a button each side and it should blink the other led of the other stm using interrupt at the reception from master to slave is ok but slave to master nthg happend??

when i see this exemple repositry looks like its possible in stm32f103 series

Posted on January 22, 2018 at 12:10

i took a look to docs you send me thank you, so as i understood what suits my issue is to make multi master isnt it ?

how can i do that

 HAL_I2C_Master_Transmit(&hi2c2,0,data_master,1,50)  on both  sides ???also it blokes both sides

, which receiving interrupt is suitable for me on both sides :

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

or 

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

Posted on January 22, 2018 at 12:21

TARHAN SAMAH wrote:

what suits my issue is to make multi master isnt it ?

I would not recommend that - certainly not for a beginner!

See: 

https://community.st.com/0D50X00009XkXwGSAV

 

And: 

https://community.st.com/0D50X00009XkXwGSAV

 

More conventional approaches would be, for example,

  1. The master polls the slave at suitable intervals;
  2. The slave has some sort of 'alert' signal to the Master - which tells it to read the Slave.

    (this is exactly what things like the well-known PCF8574 do)
TARHAN SAMAH
Senior
Posted on January 22, 2018 at 15:43

now i make like you suggest me Mister 

Andrew Neil

2.The slave has some sort of 'alert' signal to the Master - which tells it to read the Slave.

(this is exactly what things like the well-known PCF8574 do)

even if the master gives to slave to right to send it cannot send anything 

from the other side i tried both of them 

HAL_I2C_Master_Transmit(&hi2c2,0,data_master,1,50);//master sends data to slave

HAL_I2C_Slave_Transmit(&hi2c2,data_master,1,50);//master sends data to slave

very strange !!!!

datenschleuder
Associate

Did you managed to find a solution for this strange behavior?

I have exact the same problem and could not find a solution for this.

Master sends data to slave via I2C fine, but the Slave sends only zeros back to the master via HAL_I2C_Slave_Transmit(&hi2c1, buffer, BUFFERSIZE, 5000); which returns with HAL_OK.

The picture above shows sending two bytes from master to slave and 1 byte back from slave to master, but the data is always zero.

0690X0000089DrXQAU.png