Reading from BMI055 on STM32F4 I2C2

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Reading from BMI055 on STM32F4 I2C2

Post by hkerner »

Hi there,

I am trying to read from gyro data on a bmi055 using an STM32F4. The gyro is on I2C2 and I have followed the example in testhal and pored over the troubleshooting guide but when I call i2cMasterTransmitTimeout() it always times out, and if I do just i2cMasterTransmit() it never returns.

Here is my setup:

Code: Select all

  palSetPadMode(GPIOF, 1, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);   /* SCL */
  palSetPadMode(GPIOF, 0, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);   /* SDA */
  i2cStart(&I2CD2, &i2cfg2);


with the config:

Code: Select all

/* I2C interface #2 */
static const I2CConfig i2cfg2 = {
    OPMODE_I2C,
    400000,
    FAST_DUTY_CYCLE_2,
};


I was previously implementing this with libopencm3 and I used 100KHz as the speed but when I use that here it just breaks.
Here is where I am doing the read:

Code: Select all

static uint8_t data_out[8];  // tx_buf
static uint8_t rx_buf[8];
static i2cflags_t errors = 0;
static const uint8_t id_register = 0x00;
#define bmi055_addr 0b1101001

  systime_t tmo = MS2ST(500);
  msg_t status;
  // Query GYRO "CHIP_ID" register
  data_out[0] = id_register;
  i2cAcquireBus(&I2CD2);
  status = i2cMasterTransmitTimeout(&I2CD2, bmi055_addr, data_out, 1, rx_buf, 1, tmo);
  i2cReleaseBus(&I2CD2);
  if (status != RDY_OK) {
    if (status == RDY_RESET) {
      errors = i2cGetErrors(&I2CD2);
    }
    if (status == RDY_TIMEOUT) {
      _printf("Timeout occurred");
      palTogglePad(GPIOA, 1);
    }
  }


Do you see anything I'm doing inherently wrong here? Thank you in advance.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reading from BMI055 on STM32F4 I2C2

Post by Giovanni »

Hi,

The code looks OK.

Please follow this guide: http://www.chibios.org/dokuwiki/doku.ph ... e_shooting

Most common problems are explained there.

Giovanni
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Reading from BMI055 on STM32F4 I2C2

Post by hkerner »

Thanks, I have pored over that page actually and have made sure I'm doing all of those things correctly. I have things working fine with the Serial Driver. However I think the problem lies in the fact that I'm using the STM32F407-DISCOVERY board files for the STM32F417IG.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reading from BMI055 on STM32F4 I2C2

Post by Giovanni »

hi,

Board files are highly specific, you need to create new ones.

ChibiStudio includes a board files generator that takes in input an XML description, see those .chcfg files in many board directories.

Giovanni
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Reading from BMI055 on STM32F4 I2C2

Post by hkerner »

Thank you! I will look at that. In the troubleshooting page it says "Ensure SDA/SCL lines not swapped." but I have not specified anywhere exactly what the SDA/SCL lines are, other than configuring the pins for them appropriately in the board.h file. Is there a particular place where I specify what those lines are?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reading from BMI055 on STM32F4 I2C2

Post by Giovanni »

It just means that you have to make sure that your device is connected properly.

Giovanni
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: Reading from BMI055 on STM32F4 I2C2

Post by hkerner »

Ok thanks. I am creating the board.h file using the .chcfg file, but I don't have ChibiStudio. Is there a way to generate the .h file without using ChibiStudio?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reading from BMI055 on STM32F4 I2C2

Post by Giovanni »

Currently not.

Giovanni
Post Reply