AnsweredAssumed Answered

Receiving register address byte with STM32F407 as I2C slave

Question asked by ellis.andrew.001 on Jun 15, 2016
Latest reply on Jun 15, 2016 by ellis.andrew.001

I have written a small proeject where I have set up an STM32F407 on a discovery board as an I2C slave, and I'm pleased to say that it is mostly working. The problem I have is that when I send the following three bytes from the master:

0x30 // I2C slave address
0x02 // I2C device register
0xAA // Data

I can see with a logic analyser that all three bytes are acknowledged by the slave, but I'm not able to read the register byte in the void I2C1_EV_IRQHandler(). The slave address is caught by
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:, and the data byte is picked up by
buf[0] = I2C_ReceiveData(I2C1);

I'm not able to pick up the register value by a call to I2C_ReceiveData(). When I call I2C_ReceiveData() at
I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED, on the first attempt the value I get is the 0, and on subsequent attempts it is the same value as the data byte. I have tried calling I2C_ReceiveData() twice at I2C_EVENT_SLAVE_BYTE_RECEIVED, but I get the same value twice. I2C_EVENT_SLAVE_BYTE_RECEIVED is only trapped once per transaction.

What event do I need to trap to be able to read the register byte?

Kind regards