MPU9250 Driver in SPI mode

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

MPU9250 Driver in SPI mode

Moses
I build a AutoPilot board with STM32F405 core board + MS5611 sensor + MPU9250 in I2C mode, It work smoothly when trial flight. But when i try let MPU9250 work in SPI mode, I find i can't use imu_mpu9250_spi in xml file.
My question:
Does PPZ support MPU9250 SPI mode now? or it will be driven in future?
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Gautier Hattenberger-3
Hi,

I wrote the MPU9250 driver (based on MPU6050) but only tested it on I2C.
So if you want to use the SPI version, you will have to finish the work.
Hopefully it means you just have to make the makefile for the SPI
version in conf/firmwares/subsystems/shared and it will work straight...

Gautier

Le 14/04/2015 01:40, Moses a écrit :

> I build a AutoPilot board with STM32F405 core board + MS5611 sensor + MPU9250
> in I2C mode, It work smoothly when trial flight. But when i try let MPU9250
> work in SPI mode, I find i can't use imu_mpu9250_spi in xml file.
> My question:
> Does PPZ support MPU9250 SPI mode now? or it will be driven in future?
>
>
>
> --
> View this message in context: http://lists.paparazziuav.org/MPU9250-Driver-in-SPI-mode-tp16954.html
> Sent from the paparazzi-devel mailing list archive at Nabble.com.
>
> _______________________________________________
> Paparazzi-devel mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/paparazzi-devel


_______________________________________________
Paparazzi-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/paparazzi-devel
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Moses
Hi Gautier,
        Thanks for you code in MPU9250 IIC. I will try to finish the SPI makefile and test it in my board, when that finished I will note you, maybe you can review it.
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

flixr
Administrator
Hi,

I added the SPI version for the mpu9250 in the mpu9250_spi branch with https://github.com/paparazzi/paparazzi/commit/5e9cc9226d352e0508b21de1a361d2f9f924051e
It is completely untested and I don't know if configuring and reading the mag through spi works like it is.
To try to also read the mag, define IMU_MPU9250_READ_MAG to TRUE

Cheers, Felix

On Tue, Apr 14, 2015 at 4:23 PM, Moses <[hidden email]> wrote:
Hi Gautier,
        Thanks for you code in MPU9250 IIC. I will try to finish the SPI
makefile and test it in my board, when that finished I will note you, maybe
you can review it.



--
View this message in context: http://lists.paparazziuav.org/MPU9250-Driver-in-SPI-mode-tp16954p16960.html
Sent from the paparazzi-devel mailing list archive at Nabble.com.

_______________________________________________
Paparazzi-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/paparazzi-devel


_______________________________________________
Paparazzi-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/paparazzi-devel
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Moses
Hi flixr,

Thanks for your help, I will start base you branch.
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Moses
In reply to this post by flixr
Hi,

I finished IMU MPU9250 SPI and opened a pull request. It run ok in GSC but I haven't test it with my rotorcraft.
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Bubbachuck
This post has NOT been accepted by the mailing list yet.
Hello Moses,

From the codes, SLAVE4 is used in imu_mpu9250_spi, is there an extended device used in your test evironment?

It seems that AK8963 can be accessed from SLAVE0 according to MPU9250 datasheet. Could you please share me more information?

Thanks.

Moses wrote
Hi,

I finished IMU MPU9250 SPI and opened a pull request. It run ok in GSC but I haven't test it with my rotorcraft.
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Moses
AK8963 has been accessed as slave device through I2C in the SPI driver.
1 pressure sensor(MS5611 IIC) + 1 OSD(MAX7456 SPI) + 1 9DOF(MPU9250 SPI) in my autopilot.

STM32MCU
 |
 |---------SPI2----------mpu9250----(IIC)--------AK8963
 |
 |---------SPI1---------max7456
 |
 |---------IIC-----------ms5611


btw: SLAVE4 is means the NCS(or NSS)pin of mpu9250 that nothing with IIC address. MPU9250 should send back a lot of data in DMA mode, add any other extended device in the same SPI bus is not a good idea.  
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Bubbachuck
Thanks for your quick response.

I was confused that AK8963 is configured with SLV4 registers but read from SLV0. See the following codes:


bool_t imu_mpu9250_configure_mag_slave(Mpu9250ConfigSet mpu_set, void *mpu)
{
  // wait before starting the configuration of the mag
  // doing to early may void the mode configuration
  if (get_sys_time_float() < IMU_MPU9250_MAG_STARTUP_DELAY) {
    return FALSE;
  }

  //config AK8963 soft reset
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_ADDR, (MPU9250_MAG_ADDR >> 1));
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_REG, AK8963_REG_CNTL2);
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_DO, 1);
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_CTRL, (1 << 7)); // Slave 4 enable

  mpu_wait_slave4_ready();

  // Set it to continious measuring mode 2
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_ADDR, (MPU9250_MAG_ADDR >> 1));
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_REG, AK8963_REG_CNTL1);
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_DO, AK8963_CNTL1_CM_2);
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV4_CTRL, (1 << 7)); // Slave 4 enable

  mpu_wait_slave4_ready();

  //Config SLV0 for continus Read
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV0_ADDR, (MPU9250_MAG_ADDR >> 1) | MPU9250_SPI_READ);
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV0_REG, AK8963_REG_HXL);
  // Put the enable command as last.
  mpu_set_and_wait(mpu_set, mpu, MPU9250_REG_I2C_SLV0_CTRL,
                   (1 << 7) |    // Slave 0 enable
                   (7 << 0));    // Read 7 bytes (mag x,y,z + status)

  return TRUE;
}


Moses wrote
AK8963 has been accessed as slave device through I2C in the SPI driver.
1 pressure sensor(MS5611 IIC) + 1 OSD(MAX7456 SPI) + 1 9DOF(MPU9250 SPI) in my autopilot.

STM32MCU
 |
 |---------SPI2----------mpu9250----(IIC)--------AK8963
 |
 |---------SPI1---------max7456
 |
 |---------IIC-----------ms5611


btw: SLAVE4 is means the NCS(or NSS)pin of mpu9250 that nothing with IIC address. MPU9250 should send back a lot of data in DMA mode, add any other extended device in the same SPI bus is not a good idea.
Reply | Threaded
Open this post in threaded view
|

Re: MPU9250 Driver in SPI mode

Moses
Complex: you should read MPU9250 Register Map and Descriptions it have all info.

Simple: MPU9250 I2C SLV4 is easy to init a device(I2C_SLV4_DO/I2C_SLV4_DI),  most of time you can init device with SLV4 and read data continues with SLV0-3.