2018-01-22 01:06 AM
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) { } // }}//BUTTONthis function always fails, can you advice me plz
2018-01-22 02:46 AM
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
2018-01-22 03:54 AM
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
2018-01-22 04:10 AM
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
2018-01-22 04:21 AM
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,
2018-01-22 06:43 AM
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 !!!!
2019-03-29 03:14 AM
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.