2025-06-03 8:51 AM
Hello,
i use a STM32G051K6 with LL Drivers and want to implement I2C. But all the time it sends Slave ID, 0x01, Byte 1, 2 and so on. Here i Call 0x38 Slave ID:
And here all Data:
And this my Code:
LL_I2C_TransmitData8(I2C1, 0x00);
LL_I2C_HandleTransfer(I2C1, 0x70, LL_I2C_ADDRSLAVE_7BIT, 3, LL_I2C_MODE_SOFTEND, LL_I2C_GENERATE_START_WRITE);
LL_mDelay(1);
for (int i = 0; i < 3; i++) {
while (!LL_I2C_IsActiveFlag_TXE(I2C1)); // Wait until the data register is empty
if (LL_I2C_IsActiveFlag_NACK(I2C1)) { // Check for NACK (Not Acknowledged)
return 1;
}
LL_I2C_TransmitData8(I2C1, i+10); //temp[i]); // Transmit data byte
LL_mDelay(1);
LL_I2C_ClearFlag_TXE(I2C1);
}
LL_I2C_GenerateStopCondition(I2C1);
LL_mDelay(1);
LL_I2C_ClearFlag_STOP(I2C1);
I Hope you can help me with this Topic :)
BR rspecht
2025-06-03 11:43 AM
Here's some example code that uses LL I2C calls:
2025-06-03 12:32 PM
Thank you.
I tried like in the link but with nearly the same result. Now it doesn't increment the send data - so i think the loop fills the Buffer more then one time in a for increment but the 0x01 stays the same - even if i decrease the send bytes to 1. Also 10 Bytes begin with a 0x01 after the Slave Write Command.
LL_I2C_HandleTransfer(I2C1, 0x70, LL_I2C_ADDRSLAVE_7BIT, 3, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
LL_mDelay(1);
for (int i = 0; i < 3; i++) {
while (!LL_I2C_IsActiveFlag_STOP(I2C1)) {
if (LL_I2C_IsActiveFlag_TXIS(I2C1))
{
LL_I2C_TransmitData8(I2C1, i+12);
}
}
LL_mDelay(1);
}
LL_I2C_GenerateStopCondition(I2C1);
LL_mDelay(1);
LL_I2C_ClearFlag_STOP(I2C1);
2025-06-03 11:49 PM
Hello,
i am a step into... I Debugged it and have seen that I2C_TXDR holds 0x01 while i start the transmission. But there is also I2C_ISR->TXE set so i can't write TXDR.
Now i flush TXE and then i can write in the Register - everything works now fine.
BR