Skip to main content

External SPI

The External SPI connector (CN7) brings out SPI4 with two chip selects, for sensors that need SPI's speed, such as optical flow and barometers.

Connector​

PinSignalMCU
1+5V—
2EX_SPI_SCKSPI4 SCLK (PE2)
3EX_SPI_MISOSPI4 MISO (PE13)
4EX_SPI_MOSISPI4 MOSI (PE6)
5EX_SPI_CS1SPI4 CS1 (PC13)
6EX_SPI_CS2SPI4 CS2 (PC14)
7GND—

The signal lines are 3.3 V logic. Pin 1 supplies 5 V for the device's power; use a device with its own 3.3 V regulator, or a level-compatible module. Keep the cable short for clean signals at sensor clock rates.

Drivers in the Standard Firmware​

DeviceDriverTypical chip select
PMW3901 optical flowpmw3901CS1
MS5611 barometerms5611CS2

Both have been tested on this port on the production test jig. Other PX4 SPI sensor drivers can be used with a custom build that includes them.

Starting a Device​

External SPI devices are not started automatically. Start them with the driver's external-bus options:

pmw3901 -S -b 1 -c 1 start      # optical flow on CS1
ms5611 -S -b 1 -c 2 start # barometer on CS2
OptionMeaning
-SExternal SPI bus
-b 1First external SPI bus (SPI4, the only one on the 305ap)
-c 1 / -c 2Chip select CS1 / CS2

The driver prints the device and bus when it starts, or no instance started if the device didn't answer.

To start a device at every boot, add the line to /fs/microsd/etc/extras.txt on the SD card (see Custom Firmware).

Checking the Device​

listener sensor_optical_flow
listener sensor_baro

The device's device_id decodes to bus type SPI, bus 4. A second barometer is used by PX4's sensor voting alongside the onboard BMP581.

Optical Flow Setup​

After the PMW3901 is running, set it up for position estimation:

  • Mount it facing down, and set SENS_FLOW_ROT if it is rotated.
  • Enable optical flow fusion in EKF2 (EKF2_OF_CTRL = 1).
  • A downward rangefinder improves flow-based position hold considerably.

See the PX4 optical flow documentation.