AnsweredAssumed Answered

CHIBIOS :STM32f3discovery - I2c interface with the MPL3115a2 sensor

Question asked by zaccone.giancarlo on Mar 28, 2014
Latest reply on Apr 2, 2014 by sung.chen_chung
Hi everybody,
for my first project i want to use the MPL3115a2 sensor with the stm32f3discovery with the i2c protocol After many attempts i see nothing..(the value of the pressure is always zero)...what's wrong with it?
the pin connections for the MPL21115a2 are :
PA10 for SDA i2c data
PA9  for SCL i2c clock
other pin to manage? (from the datasheet ...i think no)
for the i2c configuration i'm using the example of the lsm303dlhc sensor...
a code snippet is here :
//I2C Configuration Parameter.....from the lsm303dlhc example
static const I2CConfig i2cconfig = {
  STM32_TIMINGR_PRESC(8U)  | STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) |
  STM32_TIMINGR_SCLH(3U)   | STM32_TIMINGR_SCLL(9U),
  0,
  0
};
 
 
void padInit(void){
 
//PAD SETTING
//PA10 is SDA
//PA9 is SCL
//miss something?
  palSetPadMode(GPIOA, GPIOA_PIN9 ,       /*  pad settings for I2CD1 SCL  */
                    PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN |
                    PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING);
 
  palSetPadMode(GPIOA, GPIOA_PIN10,       /*  pad settings for I2CD1 SDA  */
                   PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN |
                   PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING);
}
 
int main(void) {
 
  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   * - Setting pin for gyroscope and accelerometer\magnetometer
   */
  halInit();
  chSysInit();
  padInit();
 
  /*
   * Initializes a serial-over-USB CDC driver.
   */
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);
 
  /*
   * Activates the USB driver and then the USB bus pull-up on D+.
   * Note, a delay is inserted in order to not have to disconnect the cable
   * after a reset.
   */
  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);
 
  int status;
  float pressure;
 
  while (TRUE) {
 
       palSetPad(GPIOE, GPIOE_LED3_RED);
       chThdSleepMilliseconds(125);
       palClearPad(GPIOE, GPIOE_LED3_RED);
       chThdSleepMilliseconds(125);
 
      //set active the power mode of the sensor...all the address are correct...
       i2cAcquireBus(&I2CD2);
      status = SetPowerMode(&I2CD2, MPL3115A2_DEFAULT_ADDR, ACTIVE);
       i2cReleaseBus (&I2CD2);
 
      //read the pressure
       i2cAcquireBus(&I2CD2);
       i2cStart(&I2CD2, &i2cconfig);
       ReadPressure(&I2CD2, MPL3115A2_DEFAULT_ADDR,&pressure);
       i2cStop(&I2CD2);
       i2cReleaseBus (&I2CD2);
      
      chprintf(chp, "MPL3115A2 pressure = %d \n" , pressure);      
 
      //set in stanby the sensor
      i2cAcquireBus(&I2CD2);
      SetPowerMode(&I2CD2, MPL3115A2_DEFAULT_ADDR, STANDBY);
      i2cReleaseBus (&I2CD2);
 
      }
  }


thanks for any suggestion

giancarlo


Outcomes