cancel
Showing results for 
Search instead for 
Did you mean: 

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

rspecht
Associate

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

3 REPLIES 3
TDK
Super User

Here's some example code that uses LL I2C calls:

STM32CubeG0/Projects/NUCLEO-G031K8/Examples_LL/I2C/I2C_OneBoard_Communication_PollingAndIT_Init/Src/main.c at 44ae4173f7de1c2e943e3650c6472db05df78478 · STMicroelectronics/STM32CubeG0

If you feel a post has answered your question, please click "Accept as Solution".
rspecht
Associate

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

 

rspecht
Associate

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