Skip to main content
RShiv.1
Associate III
November 18, 2022
Solved

I2C not working with STM32F103C6 and STM32F103C8

we have been trying to get the I2C up on both the controller and no responses from anyone the cubeMx issue if I2C is really a problem..Kindly respond as we are trying to get I2C up ..

requesting the experience forum experts to respond.

Thanks

Ravi

This topic has been closed for replies.
AScha.3
AScha.3Best answer
Super User
November 25, 2022

from the ds you posted, i cannot say, what to do better.

now lets stop  to play blind cow . :)

so look, what drivers exist and learn/copy from them :

here sensirion gives driver for their sensor:

https://github.com/Sensirion/embedded-i2c-scd30

and many others...(also in c++, rust etc.)

https://github.com/paulvha/scd30

https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library

https://github.com/RequestForCoffee/scd30

https://github.com/adafruit/Adafruit_SCD30

https://github.com/Seeed-Studio/Seeed_SCD30

https://github.com/watterott/CO2-Ampel

https://github.com/sinewave-ee/scd30-rs

the driver by sensirion should show you, what to do.

If you feel a post has answered your question, please click on " Best Answer ".

63 replies

RShiv.1
RShiv.1Author
Associate III
November 18, 2022

attached is the code for C8 and apart from choosing C6 in cubemX rest all the code remains the same..

quick response will help us a lot..

thanks and regards

Ravi

RShiv.1
RShiv.1Author
Associate III
November 21, 2022

Hi all,

Any update on this ...we are trying it out and not getting any response..is it more to do with STMCube Mx generating I2C for I2C1 or Is there any solution with I2C2 .??...

if there is any bit banging code for this where we can try this out by making the I2C pins GPIO out...

All these possibilities shall be tried out ...Kindly let us know the approach as we are stuck at a point where STM32F103C6 or C8 needed to be used ....will be of great help if some one can respond .

thanks

Ravi

ST Technical Moderator
November 21, 2022

Hello @RShiv.1​ 

Did you tried to run the I2C example within STM32CubeF1 MCU package?

\Projects\STM32F103RB-Nucleo\Examples\I2C\

I advise you to review this article: STM32 I2C does not work and the I2C limitation in the STM32F103xC/D/E errata sheet.

Then, please have a look at this post and AN4655 which describes the steps to do I2C by SW.

Hope this helps you!

When your question is answered, please close this topic by choosing Select as Best.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
ST Technical Moderator
November 21, 2022

Hi @RShiv.1​,

I added a couple of topics for: "STM32 MCUs" and "I2C" developers to give a broader audience of this post.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
RShiv.1
RShiv.1Author
Associate III
November 21, 2022

Hi ,

As suggested and also going through the other post I have done the bitbanging approach for the I2C.

Here also I am seeing I2C_Transmit not passsing through...kindly let me know where I can change in the code for I2C_Transmit...it just hangs after the first I2Cwrite...I am not seeing any data in the SDA line at all...Let me know if you need more information.

This is for connecting Sensor SCD30 with the STM32F103C6

RShiv.1
RShiv.1Author
Associate III
November 21, 2022

I am almost trying to get the SDC as follows

This is a sample code using adruino with libraries

Python code

from scd30_i2c import SCD30

scd30 = SCD30()

scd30.set_measurement_interval(2) //address is 0x4600

scd30.start_periodic_measurement() // 0x0010

time.sleep(2)

while True:

if scd30.get_data_ready(): 0x0202

m = scd30.read_measurement() // 0x0300

if m is not None:

print(f"CO2: {m[0]:.2f}ppm, temp: {m[1]:.2f}'C, rh: {m[2]:.2f}%")

time.sleep(2)

else:

time.sleep(0.2)

RShiv.1
RShiv.1Author
Associate III
November 21, 2022

SCD_30 interface description attached

RShiv.1
RShiv.1Author
Associate III
November 21, 2022

also attached is the stm32_sw_i2c .c file for ref...timely help would be appreciated..thanks

RShiv.1
RShiv.1Author
Associate III
November 21, 2022

      printf("B4 I2C \n");

     ret = I2C_transmit(SLAVE_ADDR, _txBuffer, 4); //I2C hangs here and not seeing the data go through the line

      printf("After I2C \n");

AScha.3
Super User
November 21, 2022

>it just hangs after the first I2Cwrite.

from SCD_30 ds can see, sensor need clock-stretching after first write. ->

so: you have clock-stretching enabled ?

0693W00000WJ2EaQAL.pngin Cube ->

0693W00000WJ2DrQAL.pngand adress is ok ? 7-bit , need shift left in HAL calls.

If you feel a post has answered your question, please click on " Best Answer ".