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
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Can you provide additional info? Are you correctly setup pins and select appropriate I2C bus?
Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

barthess wrote:Hi Cyrille,
Driver works fine with my BMP085 sensor. Also, I can submit my code communicates with it. The sensor is a bit tricky.


Hi Barthess,

I don't see in your code where you initialize the i2c port with i2CConfig, i2Cinit, i2cstart ?

So how do you initialize it ?

thanks
Cyrille
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 »

It is pretty ease

Code: Select all

#include "ch.h"
#include "hal.h"

#include "i2c_pns.h"
#include "main.h"

#include "lis3.h"
#include "tmp75.h"
#include "eeprom.h"
#include "max1236.h"
#include "bmp085.h"

/* interface #1 */
static const I2CConfig i2cfg1 = {
    OPMODE_I2C,
    200000, //100000, //
    FAST_DUTY_CYCLE_16_9, //STD_DUTY_CYCLE, //
    0,
    0,
    0,
    0,
};

/* interface #2 */
static const I2CConfig i2cfg2 = {
    OPMODE_I2C,
    200000, //100000, //
    FAST_DUTY_CYCLE_16_9, //STD_DUTY_CYCLE, //
    0,
    0,
    0,
    0,
};



inline void I2CInit_pns(void){
  i2cInit();
  i2cStart(&I2CD1, &i2cfg1);
  i2cStart(&I2CD2, &i2cfg2);

  /* tune ports for I2C1*/
  palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
  palSetPadMode(IOPORT2, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
  /* tune ports for I2C2*/
  palSetPadMode(IOPORT2, 10, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
  palSetPadMode(IOPORT2, 11, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);

  /* startups */
  init_eeprom();
  init_bmp085();
  init_tmp75();
  init_max1236();
  init_lis3();
}
Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

Hi Barthess,

I have tried your code to communicate with BMP085 via the i2c driver, and I think that my calibration coeff are wrong : the first coeff is equal to 0 and the other are very similar (0; -1055; -1055; 33570; 33570; 22539; 22539; 54; 54; -11075; -11075) . As you have a good experience with the BMP085, do you think that is a i2c driver problem (speed, thread priority, delay between reads, offset...) ?

Thanks
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 »

Strange. I had no such problem with my bmp085. Try to slow down bus speed. Also, coefficients in sensor are not write protected. Are you sure they are not overwritten?
DrunkenDonkey
Posts: 124
Joined: Sun Aug 28, 2011 5:16 pm

Re: I2C implementation for STM32

Post by DrunkenDonkey »

Too few people bug barthess/Giovanni these days, that must be corrected :D

It turned out I won't be using STM32F103, but the STM32L1. Deleting some big flash-related parts of my code and switching over I saw that I2C is not supported on it. According to some "Migrating from STM32F1" document, the I2C is pinout and software identical on both devices, so I just added:
${CHIBIOS}/os/hal/platforms/STM32/i2c_lld.c \
to the platform.mk file, but wondering about the reason it is not there (don't have the cpu/kit yet, can't test)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C implementation for STM32

Post by Giovanni »

Hi,

It is not there because it hasn't been tested on STM32L yet, there is no reason it shouldn't work. Please let me know your results :-)

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 »

Hi there.
If anybody wants I2C support in STM32F2xx but do not want to develop it by himself, than he (or she) cant present me MCU (not a board) from F2 series in LQFP-100 package. I will replace STM32F103 in my almost done board with that one and will port software to it.
P.S. I know they are not too expensive, but economical fuckup happens in my country.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C implementation for STM32

Post by Giovanni »

Hi Barthess,

These days economical fuckup is everywhere apparently.

The open source project received some donations and there is also some income because advertising (3 clicks per week on average :-)), it will pay for the web hosting and there is still enough for the F2s (or even the F4s if already available), if you have a paypal account I could route you some of the donations in order to purchase those chips and do the testing.

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 »

PayPal does not work with my insane country at all (not for the sending nor for receiving of payments). Also, for example, Digikey wants 100USD for shipping to my country. Also, I embarrassed to take money, real hardware is better.
Post Reply