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 22, 2022

attaching the clock stretch main file once again for reference...kindly help us out

AScha.3
Super User
November 22, 2022

so on clk line nothing happens at all? then adress right or wrong is same, because no adress sent at all.

so problem is something else - hardware ok ? pullups ? no short ? + (i always switch on port pin pullups also + set output speed low , to reduce reflections).

If you feel a post has answered your question, please click on " Best Answer ".
RShiv.1
RShiv.1Author
Associate III
November 22, 2022

Hi,

Thanks for all your suggestion...I2C_Device_ready worked for STM32F103C8 (blue board) to which we connected the sensiron sensor. In our custom board we have used STM32F103C6...now we will change to C8..should be fine ??...

  1. Now we have also connected Spectral sensor AS7341 in the same I2C line(C8 only)...the address here is 0x39
  2. The spectral sensor we are not able to get I2C working here..any bus contention seen here let me know.
  3. can we read 2 sensors ??..will there be any issue...can I read one sensor first then again read the spectral sensor..because we need continuous data to be sent to one more controller...Let me know your thoughts on this.

Thank you very much for all your suggestions..atleast HAL_ISdevice_ready is working.

regards

Ravi

AScha.3
Super User
November 22, 2022

if F103C8 working and need not much ram/flash, xxC6 should be ok also, but you have to do make separate project and compile for C6 . (has not same ram area).

I2C can have many members on one bus line, as long as they have different adress, to talk to them.

and sda/scl lines should not be more than 50cm long , because you catch more and more errors by external EMV spikes coming to the lines .

If you feel a post has answered your question, please click on " Best Answer ".
RShiv.1
RShiv.1Author
Associate III
November 22, 2022

Hi ,

Thanks for your reply...as suggested I had created a separate project for C6 also in our custom board .

But this is where I2C is not working...but I read one more post where guys who tried on C6 mentioned that below missing piece will work for C6..but my cubeMx does not generate stm32f1xx_hal_msp.c

  • open ./Core/Src/stm32f1xx_hal_msp.c
  • find HAL_I2C_MspInit(), about line 102

   GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;

   GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

   GPIO_InitStruct.Pull = GPIO_PULLUP;

   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

This code itself is not seen anywhere..any idea on this

Let me know if you have come across this so that we can change and move on...

regards

Ravi

AScha.3
Super User
November 22, 2022

I2C is now ...on pins : PB6+7 or PB8+9 ?

+

if some code is missing - just for test, copy and put it in by "hand" . :)

If you feel a post has answered your question, please click on " Best Answer ".
RShiv.1
RShiv.1Author
Associate III
November 22, 2022

Hi,

Yes I2C is now on PB6 and PB7...as mentuioned by you I did try adding the above code..but did not see I2C going through..anyways will try someother way..GPIO struct is not defined in HA_init()..let me see

thanks

Ravi

ONadr.1
Senior III
November 22, 2022

What is the value of the pullUp resistors for both lines? Are both lines at H level before comunication? What voltage is this level?

AScha.3
Super User
November 22, 2022

come on...read about I2C first - at least the basics.

yes, both hi , 3.3V if chips running on 3v3. and typical 4k7 pullups on every line.

read:

https://www.nxp.com/docs/en/application-note/AN10216.pdf

If you feel a post has answered your question, please click on " Best Answer ".
RShiv.1
RShiv.1Author
Associate III
November 22, 2022

yes absoulutely...3V3 ..we are seeing high...4K7 pulls up ..

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

Hi,

As I was continuing with my effort to read the sensor values using C8...I observed that when I do the HAL_write and HAL_Read...there seems to be values which are not coming out of sensor properly..

attached is the code for the same.I am seeing values like dd, dd once I read from the memory.

HAL_write is passing..I am comparing the same result with Rpi when I connect the sensor..so it is not matching with Rpi..Let me know your thoughts on this.

Thanks and regards

Ravi

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

also would like to add..according to the sensor doc ...there is CRC start...so we need to add this??..

I also added the same but did not seem to make much difference