cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to communicate to external peripheral device using I2C.

NPaba
Associate II

I am using STM8L Discovery board, and want to communicate with external memory and humidity sensor which requires I2C protocol for communication.

I am using STM8l15x standard peripheral library, but unable to communicate. I found the following problems while debug:

  1. If not connecting any pull-up resistor, not getting acknowledgment from slave device and getting stuck in while((I2C1->SR1 & I2C_SR1_ADDR) == 0) loop
  2. If connecting pull-up resistor on both SDA and SCL (1k and 4.7K tried), unable to generate start condition.

Please help me out how can I resolve it?

Thank you so much in advance.

13 REPLIES 13
Cristian Gyorgy
Senior III

The i2c bus needs pull-up resistors on both lines (SCL, SDA), it cannot work without them.

I just checked the STM8L Disco. board schematics: your SB17 jumper needs to be open, so that the blue button is not functional anymore.

How do you know it cannot generate the start condition? Post some more info and maybe the relevant part of your software.

NPaba
Associate II

Hello Cristian,

First of all thank you very much for your reply, and sorry for late reply from my side.

How do you know it cannot generate the start condition?

-> I am using standard peripheral library of stm8l152, where by putting breakpoint (code get stuck here:while(!(I2C1->SR1 & 0x02); I observed that start condition is not generated. But now I am able to generate start condition even with pull up resistor.

Still there is no acknowledgement from slave.

I just checked the STM8L Disco. board schematics: your SB17 jumper needs to be open, so that the blue button is not functional anymore.

-> For this I need to desolder the jumper. Let me try this.

Thank you ;)

S.Ma
Principal

Dusting off my old ST7/STM8 I2C bit bang code from 2003...

As salesforce can't import more than a single file (thank god, we don't need to comply with 8 ASCII . 3 ASCII filename...

one more

	#define I2C_DELAY 4 //2
 
	#define GPIO_SM2_I2C_SCL               	            	GPIOC,GPIO_Pin_1
	#define GPIO_SM2_I2C_SDA               	            	GPIOC,GPIO_Pin_0

S.Ma
Principal

It's rustly and I've got something a bit cleaner for STM32. Used it with many humidity sensors (ST, Honeywell, Bosch, (Sensirion is not supported as it's the only sensor with clock stretching), etc...). Functionally rugged like a hummer.

Hello Cristian,

I tried by removing the SB17 jumper, but still the issue is same.

Please help.

I am using this file.

Slave device: EEPROM - 24AA512, device address 0x50

I will have a look on the code you posted, until than I noticed you say the device address is 0x50 - this shouldn't be right, as the 24AA512 EEPROM should have an address starting with 0xA (0xA0 if you tied the A0,A1,A2 device select inputs to ground and you start a write transfer, or 0xA1 if you start a read transfer with the same inpts to ground).

If the slave address is not correct, it will not acknowledge your transfer.

Hello Cristian,

Yes it was my mistake, the address is 0xA0 and not 0x50. I will try this address and let you know.

Thank you very much for your continuous support.