cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Nucleo I2C Slave answer with Interrupt

SBühl.1
Associate

Hello, everyone

I'm trying to make an I2C slave with a Nucleo-F401RE.

Writing from Master (Raspberry) to Slave (Nucleo) works very well.

But the response of the Slave (Nucleo) to a read command from the master (Raspberry) does not work.

I tried a very simple code (see below). The Slave should transmit 0x2F as a response.

But it transmits 0x11 every time.

I really do not know how to continue. I would be grateful for any help!

0693W00000DlqjxQAB.png

uint16_t Size = 1;
uint8_t Data = 0x2F;
 
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
  HAL_I2C_Slave_Transmit_IT(&hi2c2, &Data, Size);
}
 
int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_I2C2_Init();
 
  HAL_I2C_Slave_Transmit_IT(&hi2c2, &Data, Size);
 
  while(1)
  {
     __NOP();
  }
}

0693W00000DlqlKQAR.jpg

1 REPLY 1
Bubbles
ST Employee

Hi @Stephan Bühler​ ,

what you describe is a weird way of using the I2C. In most cases the Master writes a command to the slave, slave is not supposed to transmit command to a master node. For slave to transmit, the master needs to set the read bit in address to indicate that slave is supposed to transmit it's reply. For example SMBus is closely related to I2C and you can see AN4502 and the related SW example to see how the exchange usually goes.

J.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.