SPI configuration

Hi ! :slight_smile:

I’m trying to change the SPI number for MPU9250. (SPI1 → SPI2)

I think the SPI initialization has no problem, but the connection with MPU9250 is not established.

So, I can find the probe error (‘MPU9250_SPI::probe()’ function in ‘mpu9250_spi.cpp’ file). The ‘whoami’ value is set to ‘0’ and CS pin is actived.

I tried to use both the other CS, DRDY pins and original pins.

In addition, what does the ‘bus’ mean? and how is it set up?

If you look at the MPU9250 driver, you will see that it is trying to use the PX4_SPI_BUS_SENSORS bus as the SPI bus. This bus is set in the board_config.h file for the board (remember there is a board_config.h for each board). In board_config.h you will probably see something like this:

#define PX4_SPI_BUS_SENSORS          1
#define PX4_SPI_BUS_RAMTRON          2
#define PX4_SPI_BUS_BARO PX4_SPI_BUS_RAMTRON

If you change the PX4_SPI_BUS_SENSORS bus to be 2, then in px4fmu_spi.c then you will also have to change the SPI select function from stm32_spi1select() to be stm32_spi2select().

But be careful. If you change the MPU9250 to be on another SPI bus, are you changing all of your sensors for your new board to be on this new bus. The one assumption that is made in most of the Px4 sensor drivers is that the onboard sensors are all on the same PX4_SPI_BUS_SENSORS bus.

1 Like

I changed the PX4_SPI_BUS_SENSORS and solved this problem !!

Thank you for your help ^^ :slight_smile:

You will just have to be careful about adding other sensors to the bus and make sure that the stm32_spi2select() function is adapted appropriately for the additional sensors that you add.