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: 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 » Tue Jan 10, 2012 7:20 pm

Fixed thanks :-)

Giovanni

matis
Posts: 53
Joined: Fri Jul 01, 2011 1:46 pm

Re: I2C implementation for STM32

Postby matis » Thu Jan 19, 2012 4:33 pm

Subtle kick :D

I'm currently getting at the most difficult and challenging part of my I2C development at my F103VET6. We have two tracks connected to pin 55 and 56 (PD8 and PD9 respectively) for I2C communication, where the STM32 would be the I2C-slave.
Is there any software (bit-banged) I2C driver for that purpose available? I've depleted both the I2C1 and I2C2 lowlevel I2C nodes as I2C-master.
In the first posts there was a bit of an argue about this bit-banged I2C driver, but I'm not quite sure if that development ever got started.

Matis

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 » Thu Jan 19, 2012 4:55 pm

It is 30% done but it would be a master I2C driver not a slave one. Probably I will complete it after the 2.4.0 release.

BTW, STM32F2 and F4 have 3 I2C ports.

Giovanni

matis
Posts: 53
Joined: Fri Jul 01, 2011 1:46 pm

Re: I2C implementation for STM32

Postby matis » Thu Jan 19, 2012 5:04 pm

Hmm, that's quite a bummer :roll: No flame intended btw, I don't think that redesigning the PCB with a F2 or F4 is really an option.
We want to daisy chain several STM32's and I2C seemed to be the easiest 2-wire protocol to implement, but not if the software isn't there.

Can / do you suggest any other 2-wire interface that we can use?

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 » Thu Jan 19, 2012 5:09 pm

USARTs 1, 2 or 3 could be used through the UART driver, of course you have to implement a SW protocol. Two wires, bidirectional and not slower than an I2C.

Giovanni

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 Jan 30, 2012 4:23 pm

I've been noticing some strange behaviour on a cold power up of my board when using i2c. I find the i2c write commands to initialise my sensors (MPU6050, LSM303DLM) time out for a second or two (I need to establish if it is just one of the sensors which is unstable), before eventually completing successfully. But then sometimes, when I go to read the device the system locks. I don't think it is as a result of chSysHalt() being called because I added some code to the macro to set an led and that never gets called. But I'm not sure how I can debug this as it only occurs intermittently, and only ever on first power-up after being unpowered for a while. If I reset the circuit then it works fine! So there is probably some power supply issue with my board, but also something in the software isn't quite handling the errors correctly.

Hmmm. I've been stuck on this one for a while! :D

p.s this page needs more pictures, so here is my new board! So far there are no green wires soldered on top..
Image

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 Jan 30, 2012 5:15 pm

Hi Badger,
I use similar to your MPU6050 sensor (ITG-3200).
1) It must be powered on in not trivial way. Look in datasheet "7.4 Recommended Power-on Procedure". Can you scope power supply ramps?
2) There must be pauses between configuration commands. In my case the sensor can not generate interrupts without that pauses. May be some other bugs there.
3) Try to increase IRQ and DMA priorities of I2C bus. There were arbitration loss errors on the bus when priority too low (in my case).

UPDATE:
Are you send soft reset command to the sensor?

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 Jan 30, 2012 5:27 pm

Could it be related to how JTAGs operate? they usually run the target, then reset then stop. It is possible the target is reset during an operation and the bus is left in a locked state that triggers the timeout on next execution.

It would be interesting to verify if the problem persists without the debugger attached, just a clean power up.

Giovanni

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 Jan 30, 2012 5:42 pm

Thanks for the pointers barthess, I added some conservative configuration delays. So far it looks stable on power up, but the problem was intermittent; I'll keep testing to see if that fixed it.

I hadn't paid much attention to the proper power supply ramping as it generally seemed to work 'well enough' (I must stop copying sparkfun breakout boards, they always miss the little details!). That is probably the cause of the sensor instability, and something I need to resolve. I've only recently purchased a scope (a cheapo Rigol DS1052E) and have previously only used them for capturing stationary waveforms, so I'll need to work out how to capture the power supply ramps.

Giovanni, This is running without the JTAG, powered over USB. I was hoping to use JTAG to find out where in the code it crashes, but I can't work out how to get jtag to start debugging and power it up quick enough to trigger the fault!

Does this suggest that there is an error state that the i2c driver can get stuck in?

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 Jan 30, 2012 5:56 pm

Badger wrote:Does this suggest that there is an error state that the i2c driver can get stuck in?

Driver can not stuck by design. Even if slave pull down the line forever. Just do not use TIME_INFINITE timeouts for transaction.


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 1 guest