2021-09-01 02:58 AM
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!
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();
}
}
2021-09-06 02:50 AM
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.