cancel
Showing results for 
Search instead for 
Did you mean: 

I2C not working with STM32F103C6 and STM32F103C8

RShiv.1
Senior

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

63 REPLIES 63
RShiv.1
Senior

*code is not entering into these loops at all..that is why I2C is failing..that means is the address not specified properly??..or Need to enable something else...???

RShiv.1
Senior

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

AScha.3
Chief II

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 "Accept as Solution".
RShiv.1
Senior

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
Chief II

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 "Accept as Solution".
RShiv.1
Senior

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
Chief II

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 "Accept as Solution".
ONadr.1
Senior III

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
Chief II

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 "Accept as Solution".

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