cancel
Showing results for 
Search instead for 
Did you mean: 

I2C error in sending data (for the oscilloscope)

Xenon02
Senior

Hello ! 

I've got a problem because I tried to check the SDA and SCL pins like in the picture : 

Xenon02_0-1700670192061.png

 


Sorry for the paint picture (the oscilloscope was during classes so I don't have it right now).
The output was all the time noises even thought the code was correct. 

  uint8_t data = 0;
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

	  HAL_I2C_Master_Transmit(&hi2c3, 0xA0, &data, 1, 100);
	  
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}


I've had this error : 

Xenon02_1-1700670341278.png

I don't know if this Timeout is because the I2C didn't receive the ACK bit ? 

But when I've added the pull up resistors : 

Xenon02_2-1700670423029.png

The error was then this part : 

Xenon02_3-1700670458974.png



I don't really much know what happened though. 
Maybe if I want to check the I2C in oscilloscope I have to connect an I2C slave ? 
But I don't understand why I had 2 different errors. 

In RM for STM32 Nucleo-L073RZ I found this : 

Xenon02_4-1700670585480.png

I don't know if I2C_RXDR is the ACK bit that Master is now an input and waits for this ACK/I2C_RXDR ? Maybe but this stretch was maybe a timeout ? 

I got a bit confused. Is master receiving more data through SDA (or maybe SLC although it is only a clock), not just only Start, Stop, ACK and data ? 

Also the Transmission is different because it stretches the clock after ACK and Receiver before ACK, weird, somebody knows why ? 

Thanks ! 

10 REPLIES 10

Without pull-ups externally or within the GPIO, and OD (Open Drain) pin is never going to get above zero, it's just float or get clamped at zero.

Not sure if the STM32 observes if the pin goes high/low as it drives, but might as a means to tell if the bus is working.

If there is no Slave to respond to it's own address, going to fail at that stage.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

So I need to add OD ? 
Because it's all connected to the Oscilloscope. But didn't understand what those 2 errors means, one without pull up and one with pull up. Because it doesn't want to finish this mem_write command hence the while doesn't continue to repeat. I'm trying to figure it out because it is possible as I've heard to see the transmission from the oscilloscope but it didn't work in my case and the code is stuck.

I don't know if I can do this type of sending to the Oscilloscope directly. 

The I2C pins must be configured as open-drain.

The pullup resistors are required.

Of course you can use the scope to observe the signals if it's set up properly.

As I check in CubeIDE, the I2C pins were open-drains, and the pull up resistors were also added, but the final result was that it always showed error and could return from HAL_I2C_Master_Transmit/HAL_I2C_Mem_Write. The output was also noises. Couldn't get both clear signals from SCL and SDA. 

And I wondered what those 2 error could mean then. And if I set up to see the signals I understand it will always pop out error because there is no ACK bit ? 

Paint pictures is ok , but is GND scope and board connected ? Is pullups value ??? Is to nucleo 3,3V usw...

Ahh yes you are right. The GND is indeed connected just forgot to add it on the picture. 
The resistors 3.3V is taken from the board. 

I just wondered why I didn't have a normal output but sinusoidal noises. 
And why adding resistor changes the error in function. The Transmitter from STM is the Output so the floating output shouldn't be a problem because it depends of the input, the floating input can be a problem. 

Maybe does the I2C transmitter checks the bus if SDA and SCL are high at the beggining ? If so this could make sense that the errors changed. 

Ofcourse I2C protocol have defined start and bus in other state is error

plus are you sure pin is realy used as I2C where you connect scope.

And 

HAL_I2C_Master_Transmit(&hi2c3, 0xA0, &data, 1, 100);

start transmision to slave with addr 0xA0, but you dont have it real then addr isnt ACK and this result to next error plus ofcourse no data is send.

>plus are you sure pin is realy used as I2C where you connect scope.

Yes. 

Ofcourse I2C protocol have defined start and bus in other state is error

I was just wondering because even if output is floating the result is dependent only from inputs, but if input is floating then this is a problem, if I am not wrong correct me here if I am, maybe output cannot also float because they can give random values. 

So I thought that maybe I2C checks the bus before transmiting and if it's 0 or random noises then it is error. 

1. sinusoidal on scope is fail connection or fail scope input.

2. learn I2C bus theory. On inactive state no input or output exist. Only pullups.

When you as master call traffic func, first step peripheral check if bus is free and ok only pullups...