Skip to main content
Visitor II
June 3, 2025
Question

STM32G051K6 and LL I2C sends all times 0x01 after Write to Slave

  • June 3, 2025
  • 3 replies
  • 286 views

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:

Load.png

 

And here all Data:

Load2.png

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

    This topic has been closed for replies.

    3 replies

    rspechtAuthor
    Visitor II
    June 3, 2025

    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);

     

    rspechtAuthor
    Visitor II
    June 4, 2025

    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