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
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm
Location: Bath, UK
Contact:

Re: I2C implementation for STM32

Postby Badger » Mon Apr 02, 2012 2:16 pm

This is the only device I've come across which needs delays, so I suppose it is for specific slaves. But there may well be other devices out there that need delays.

An alternative could be to implement a more configurable soft i2c implementation. If such a driver were created, should it exist as a 'platform' of the existing driver, or as an entirely new I2CSoft, potentially with more options. Or we could have a software lld which would be compatible with the current i2c driver and also a more extensive one with delays etc.

User avatar
Giovanni
Site Admin
Posts: 12749
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 696 times
Been thanked: 573 times
Contact:

Re: I2C implementation for STM32

Postby Giovanni » Mon Apr 02, 2012 2:18 pm

I have a soft I2C half done, probably it could still be useful (see missing DMAs), probably it would be a good idea to finish it.

Giovanni

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

Re: I2C implementation for STM32

Postby barthess » Mon Apr 02, 2012 6:04 pm

Hi Badger,
As described in I2C standard, if slave need some time to process data than it pulls SCL line down until all data will be processed. For example ADC MAX1236
While converting the analog input signal, the MAX1236–MAX1239 holds SCL
low (clock stretching). Once all conversions are complete, the
MAX1236–MAX1239 release SCL, allowing it to be pulled
high. The master can now clock the results out of the mem-
ory in the same order the scan conversion has been done
at a clock rate of up to 1.7MHz. SCL is stretched for a max-
imum of 8.3μs per channel

Second behavior. In 24AA EEPROM chips 5 ms delays needs to write one page to storage. During this time the IC leaves SCL floating but not response the data on bus.
Both types of IC works fine in my board with ChibiOS driver.
Are there one of your case?

User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm
Location: Bath, UK
Contact:

Re: I2C implementation for STM32

Postby Badger » Mon Apr 02, 2012 6:30 pm

The device is one of those which calls I2C something else (in this case SCCB), presumably to get around licensing. I can get around it by doing a separate write then a read, so I suppose it is probably just a bad implementation of the protocol on the part of the designers! Maybe for the soft I2C driver fancy options to do with timing could exist to get around these sorts of problems, but it doesn't look worth doing for the hardware driver.

trunet
Posts: 54
Joined: Fri Apr 06, 2012 7:18 pm

Re: I2C implementation for STM32

Postby trunet » Fri Apr 06, 2012 7:29 pm

I'm trying to make I2C works with my BMP085.

I have partial success.

The code is available on github https://github.com/trunet/TrunetCopter.

Look on src/main.c on lines 242, 243 and 244. If I comment 242, 243 and uncomment 244, the code does not work(it freezes the thread).

My I2C lines are pulled high with 4.7k resistors.

User avatar
Giovanni
Site Admin
Posts: 12749
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 696 times
Been thanked: 573 times
Contact:

Re: I2C implementation for STM32

Postby Giovanni » Fri Apr 06, 2012 7:35 pm

Hi,

I recommend to enable all the debug options in chconf.h (always recommended during development) and increase the stack size of that thread, it is possible this is just a stack overflow.

Giovanni

trunet
Posts: 54
Joined: Fri Apr 06, 2012 7:18 pm

Re: I2C implementation for STM32

Postby trunet » Fri Apr 06, 2012 7:49 pm

It works, thank you.

I'm just starting with RTOS systems with ChibiOS. What is the best way to determine stack size on threads to avoid this happening?

trunet
Posts: 54
Joined: Fri Apr 06, 2012 7:18 pm

Re: I2C implementation for STM32

Postby trunet » Fri Apr 06, 2012 7:51 pm


User avatar
Giovanni
Site Admin
Posts: 12749
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 696 times
Been thanked: 573 times
Contact:

Re: I2C implementation for STM32

Postby Giovanni » Fri Apr 06, 2012 8:15 pm

Hi,

If you create an Eclipse environment and install the ChibiOS plugin you can see the stack usage directly while debugging, the plugin+debugging options allow to catch most common RTOS-related mistakes.

Giovanni

Gereon
Posts: 1
Joined: Wed May 16, 2012 12:21 pm

Re: I2C implementation for STM32

Postby Gereon » Wed May 16, 2012 3:06 pm

Giovanni wrote:I have a soft I2C half done, probably it could still be useful (see missing DMAs), probably it would be a good idea to finish it.

Giovanni


Hi Giovanni,
I'm currently writing software for a STM32-P103 Board, which has peripherals connected over SPI and I²C using ChibiOS.
As others have stated i'm running out of DMA streams, so I was wondering if you have an unstable version of your "soft I²C" available ?
(I wouldn't mind a stable one though ;))


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 3 guests