2010-10-02 12:54 AM
STM32F108C8T6 - I2C lock-up
2011-05-17 05:09 AM
No - that makes no difference.
2011-05-17 05:09 AM
I take that back - I hadn't applied it to all places where I set a STOP condition
When I apply it to all places where I set a STOP condition - it stops hanging! :)2011-05-17 05:09 AM
I use the code below to write to an LTC4151. Your application must be similar.
void LTC4151WriteBuffer(uint8_t* pBuffer, uint8_t NumByteToWrite) { /*!< While the bus is busy */ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)) { } /*!< Send START condition */ I2C_GenerateSTART(I2C1, ENABLE); /*!< Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) { } /*!< Send address for write */ I2C_Send7bitAddress(I2C1, LTC4151Address, I2C_Direction_Transmitter); /*!< Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { } //send the reg select COMMAND byte I2C_SendData(I2C1, 0); /*!< Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { } /*!< While there is data to be written */ while(NumByteToWrite--) { /*!< Send the current byte */ I2C_SendData(I2C1, *pBuffer); /*!< Point to the next byte to be written */ pBuffer++; /*!< Test on EV8 and clear it */ while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { } } /*!< Send STOP condition */ I2C_GenerateSTOP(I2C1, ENABLE); } The fact you could fix your problem with just 5 NOPs implies a hardware timing restriction which might just be how long it takes the I2C ''engine'' to clock through to the next state. (Our posts crossed - pleased to hear it's now working.)