I2C implementation for STM32

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C implementation for STM32

Post by Giovanni »

Hi,

It is far from being complete but any software I2C implementation could be easily adapted using PAL for I/O and GPT/RTCounters for delays. If you are in a hurry it would be a good idea to search some open source implementation and just adapt it.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Trunk has been updated with additional checks of clock divider for I2C bus.
If your PCLK1 frequency is 36MHz and I2C clock is 400kHz and duty cycle is 16/9 than you will get assertion error if compiled with CH_DBG_ENABLE_ASSERTS TRUE. Fast solving of problem:
set I2C clock to 360kHz
or
set duty cycle to 2/1

More information you can found in this topic https://my.st.com/public/STe2ecommuniti ... tviews=105
genosensor
Posts: 65
Joined: Thu Oct 03, 2013 1:06 am
Has thanked: 1 time
Been thanked: 1 time

Re: I2C implementation for STM32

Post by genosensor »

Just finished reading this whole 35 page thread. It brought back not-so-fond memories...

I developed an I2C driver for the TI MSP430169 when it was first released.
It was the first MSP430 with I2C support. The silicon was very buggy.
Five months of debug before it worked well in master and slave modes. Endless corner cases.
Fortunately, we could put our own logic around the MSP430 to work around problems without resorting to busy waiting.
TI did, to their credit, completely redesign the I2C block in the MSP4302xxx parts, but we stuck with the '169.

Now, we need I2C slave support in a project involving many peer-to-peer networked STM32L1xx chips.

Questions:
It appears we could avoid the busy waits for STOP before beginning each new transaction by wiring SDA and SCL to two GPIOs configured as inputs. Interrupt on raising SDA while SCL is high signals STOP. Is this viable?
Has anyone already tried this?

I'd need to work on adding slave mode capability. The user "Z80" submitted a patch that might be a starting point.
Is there a high-level driver API for Slave Mode yet defined? Should I propose one?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C implementation for STM32

Post by Giovanni »

Hi,

I answered in the other thread, there are no plans currently and it would have to be a separate driver, not an extension of the current one.

Giovanni
kalpesh
Posts: 19
Joined: Mon Dec 09, 2019 11:53 am

Re: I2C implementation for STM32

Post by kalpesh »

Hi,

I am getting an error for I2C stating acknowledgement failure. Any ideas to solve it. I have checked the voltage on my SDA and SCL pin also, which is fine. Also according to my sensor it can be operated at 100k and 400k , and I am operating it at 400k.

Please help me in case i am doing any mistake.

Thanks
Kalpesh
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C implementation for STM32

Post by Giovanni »

Make sure that you are passing the correct address, which is the value of the upper 7 bits without the RW bit.

Giovanni
kalpesh
Posts: 19
Joined: Mon Dec 09, 2019 11:53 am

Re: I2C implementation for STM32

Post by kalpesh »

Giovanni wrote:Make sure that you are passing the correct address, which is the value of the upper 7 bits without the RW bit.

Giovanni

So It means , I should pass the slave address directly(i.e. only 7 bits to be transmitted) without the read/ write bit (Read -1, Write -0).
Post Reply