AnsweredAssumed Answered

STM32 I2C "ACK Polling"

Question asked by f.a on Jan 18, 2012
Hi all,
I need an expert advice. How to poll for ACK from addressed Slave device? The background is, if the setup has a variable count of slaves and how to get the available slaves? The second case is the M24C64 EEprom. During the internal Write cycle, the device discon-
nects itself from the bus, so I need to poll on ACK. But with my solution I get always an endless loop Between write byte and read byte function. If I use instead the do-while Delay(1) everything seems to be ok. This was very easy on an Atmega to check for ACk on device addessing, I've spent a lot of time to get this on STM32, but without success.

eeprom_wait_for_ready (void) {

    unsigned char state = 0;
        while(I2C_GetFlagStatus(I2C_SELECTED, I2C_FLAG_BUSY));

        // Send START condition
        I2C_GenerateSTART(I2C_SELECTED, ENABLE);
        // Test on EV5 and clear it
        while(!I2C_CheckEvent(I2C_SELECTED, I2C_EVENT_MASTER_MODE_SELECT));

        // Sent slave address for write
        I2C_Send7bitAddress(I2C_SELECTED, EEPROM_I2C_ADDR, I2C_Direction_Transmitter);


        I2C_GenerateSTOP(I2C_SELECTED, ENABLE);
    } while (!state);


Thx for helping.