STM32 initialization and reading problems

By scottruss , 14 September 2013

Hello!

I am trying to use the MotionDriver 5.1 with an MPU6050 conneted to STM32L152.

I use standard configuration procedure by calling the mpu_init() function.
The only difference is that I don't set the interrupt.
I have implemented logging of all possible errors and It turns out the initialization fails on mpu_set_bypass(0) function (i don't use a magnetometer).
To be precise it fails here (the first write operation to user_ctrl register):

else
{
// Enable I2C master mode if compass is being used.
if (i2c_read(st.hw->addr, st.reg->user_ctrl, 1, &tmp))
{
log_e("User control read error!n");
return -1;
}

if (st.chip_cfg.sensors & INV_XYZ_COMPASS)
tmp |= BIT_AUX_IF_EN;
else
tmp &= ~BIT_AUX_IF_EN;

//FAILS HERE
if (i2c_write(st.hw->addr, st.reg->user_ctrl, 1, &tmp))
{
log_e("Compass set error! User control register value: %dn", tmp);
return -1;
}
delay_ms(3);

if (st.chip_cfg.active_low_int)
tmp = BIT_ACTL;
else
tmp = 0;

if (st.chip_cfg.latched_int)
tmp |= BIT_LATCH_EN | BIT_ANY_RD_CLR;
if (i2c_write(st.hw->addr, st.reg->int_pin_cfg, 1, &tmp))
{
log_e("Interrupt set error!n");
return -1;
}
}


It is strange because there are multiple writes and reads before, in the mpu_init() function, and there is no problem. For example the sensor revision is read properly.

If I comment out the mpu_set_bypass(0) and go further I get an error when calling dmp_load_motion_driver_firmware(); The problem is in veryfication stage. When I read back the memory it is 0.

I also tried to use the self test function and it returns 0, which means the test fails.
I cannot get any results from the sensor, even by reading registers directly.

Have you got any idea what can be wrong?

Best,
Patrick

guy_mcilroy

12 years 5 months ago

Check your i2c_write implementation. It sounds like the i2c_write function was not implemented properly. Are you able to write to the user_ctrl register outside of this function?

phpbb Post ID
23952
phpbb Topic ID
15597