cancel
Showing results for 
Search instead for 
Did you mean: 

CHIBIOS :STM32f3discovery - I2c interface with the MPL3115a2 sensor

giancarlo
Associate
Posted on March 28, 2014 at 17:28

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 #chibios-i2c-mpl3115a2-sensor
1 REPLY 1
chen
Associate II
Posted on April 02, 2014 at 12:37

Hi

''the pin connections for the MPL21115a2 are :

PA10 for SDA i2c data

PA9 for SCL i2c clock''

Yes, these are right.

''for the i2c configuration i'm using the example of the lsm303dlhc sensor...

a code snippet is here :''

Code snipet looks OK but cannot be 100%

''After many attempts i see nothing..(the value of the pressure is always zero)...what's wrong with it?''

Do you have pull ups?

Can you see what is happening on I2C (do you have oscilloscope or logic analyser)?