# Add a new external device on SPI 4

**URL:** <https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322>\
**Category:** PX4 Autopilot\
**Created:** [April 20, 2020, 10:52am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322 "2020-04-20T10:52:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iolo](https://discuss.px4.io/user_avatar/discuss.px4.io/iolo/32/6100_2.png) [@Iolo](https://discuss.px4.io/u/Iolo)\
**Post date:** [April 20, 2020, 10:52am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/1 "2020-04-20T10:52:20Z")

</div>

I’m trying to connect LSM6DSR to my PX4, it’s running on fmu-v4, via SPI 4. How can I activate it? My module is based on the lsm303d imu from imu/st folder.  
I set the define CONFIG\_STM32\_SPI4 and I performed debug tests with printf(because it’s not enough memory with debug flag set ) and I found that: the bus is 4, but I got: instantiate failed no device on bus 4 (devid 0x10000001). It is 1 because px4\_spi\_buses has only one external driver.

‘initSPIBusExternal(SPI:🚌:SPI4, {  
initSPIConfigExternal(SPI::CS{GPIO::PortA, GPIO::Pin8}),  
}),’

Grateful for any help. This feels like it should be simple, but I can’t find the information I need.

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [April 20, 2020, 11:06am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/2 "2020-04-20T11:06:39Z")

</div>

If you put your code sample in ``` we don’t get to see the 🚌 :).

@bkueng any idea what to try out?

---

<div class="post-metadata">

**Author:** ![bkueng](https://discuss.px4.io/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bkueng](https://discuss.px4.io/u/bkueng)\
**Post date:** [April 20, 2020, 11:54am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/3 "2020-04-20T11:54:18Z")

</div>

How do you run it? -\> `lsm303d start -S`?

---

<div class="post-metadata">

**Author:** ![Iolo](https://discuss.px4.io/user_avatar/discuss.px4.io/iolo/32/6100_2.png) [@Iolo](https://discuss.px4.io/u/Iolo)\
**Post date:** [April 20, 2020, 12:01pm UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/4 "2020-04-20T12:01:33Z")

</div>

in the configuration file(rc.board\_sensors) I have: lsm303d -s -b 4 -c 2 -R 6 start and at runtime lsm303d -S -c 2 start . I saw that there is a problem: if I do not set -b4 in the config file, the chip select does not match with the bus. It’ s that true?

---

<div class="post-metadata">

**Author:** ![Moksh-2000](https://discuss.px4.io/user_avatar/discuss.px4.io/moksh-2000/32/6111_2.png) [@Moksh-2000](https://discuss.px4.io/u/Moksh-2000)\
**Post date:** [April 21, 2020, 12:11pm UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/5 "2020-04-21T12:11:38Z")

</div>

> [@Iolo](#):
>
> (rc.board\_sensors) I have: lsm303d

Hello sir I have radio link pixhawk , and company say is it available LSM303D compass sensor but QGC also MP not show any compass on my pixhawk , any suggestions , please help me.

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![bkueng](https://discuss.px4.io/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bkueng](https://discuss.px4.io/u/bkueng)\
**Post date:** [April 21, 2020, 1:28pm UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/6 "2020-04-21T13:28:28Z")

</div>

So is it working?

> [@Iolo](#):
>
> if I do not set -b4 in the config file, the chip select does not match with the bus. It’ s that true?

Only if you have multiple external buses, you need to specify it.

---

<div class="post-metadata">

**Author:** ![Iolo](https://discuss.px4.io/user_avatar/discuss.px4.io/iolo/32/6100_2.png) [@Iolo](https://discuss.px4.io/u/Iolo)\
**Post date:** [April 22, 2020, 2:44am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/7 "2020-04-22T02:44:09Z")

</div>

…no, it’s not working ☹ . The command “nameModule -S start” does not work. I have also an ADIS1647X external on SPI4 and I have the same problem. For what I understood, external means that my sensor is connected from outside the board -PixRacer R15, that means the command for running the module is: adis16475 -S -b 4 -c 1 start, where:

-S -\> external device;  
-b 4 -\> on bus 4(SPI4) or should be -b 1 because on the SPI4 I have only one device connected?  
-c 1 -\> chip select; in my case devid is 0x10000000; that means, the first CS set in the SPI4 table is the CS located in the first row of the SPI table(see the first comment). It s that true? The module ID 0x00 will be connected to that SPI4, right?  
Also, my SPI is configured as SPI 4 at the ESP8266 connector from the board(). Is this module ON when the board is powered or I need to configure it with the GUI menuconfig to deactivate it? I thought that with ADIS module will be more simple to get the data from the sensor but is not so simple because, I think, information is missing and I need to clarify it in order to understand what’s going on in the code. 🙂 Thanks 🙂

---

<div class="post-metadata">

**Author:** ![bkueng](https://discuss.px4.io/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bkueng](https://discuss.px4.io/u/bkueng)\
**Post date:** [April 22, 2020, 6:21am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/8 "2020-04-22T06:21:27Z")

</div>

First, you should not have to do any board config changes on v4. Make sure to disconnect the ESP8266, then SPI4 should be configured as external SPI.

> [@Iolo](#):
>
> -b 4 → on bus 4(SPI4) or should be -b 1 because on the SPI4 I have only one device connected?

That should be `-b 1` to select the first external bus.

> [@Iolo](#):
>
> -c 1 → chip select; in my case devid is 0x10000000; that means, the first CS set in the SPI4 table is the CS located in the first row of the SPI table(see the first comment). It s that true? The module ID 0x00 will be connected to that SPI4, right?

Correct, there’s only 1 CS configured, so you can use the default (1).

Are you using latest master?  
Did you double-check that you connected everything right?

---

<div class="post-metadata">

**Author:** ![Iolo](https://discuss.px4.io/user_avatar/discuss.px4.io/iolo/32/6100_2.png) [@Iolo](https://discuss.px4.io/u/Iolo)\
**Post date:** [April 22, 2020, 6:44am UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/9 "2020-04-22T06:44:48Z")

</div>

.1.I m not sure how to disconnect the ESP8266, only the SYS\_AUTOSTART says to me if the ESP is ON or OFF. When I run the command ps in the terminal, is not there. ![Screenshot from 2020-04-22 09-28-36](https://discuss.px4.io/uploads/default/original/2X/0/02470276bd55eedbb642f98960a88a69076a255d.png) , when I check in the ls /dev ttyS0 is there. It should not be there after config. But SYS\_AUTOSTART, in my case in 4250, I saw in the rc. board\_mavlink.  
2.Yes, I have the latest master.  
3.Yes, the Cs is (on PBA , pin 8,) good but ADIS has DRDY PB, pin 4; this is the INT. Only this DRDY I set in the table  
One question: how SPI4 know to communicate with ADIS16477/75 if it has another ID as an module? this 0x00 is calculated based on ADIS16477 ID, right? I saw something in the code and for the internal, this iD is the module sensor ID;  
Another question: what about the voltage, should be on before or after I configure the sensor. I saw in another board spi config, fmu-v5, this comment:  
‘’// initSPIBus(SPI: 🚌:SPI4, {

// // no devices

// TODO: if enabled, remove GPIO\_VDD\_3V3\_SENSORS4\_EN from board\_config.h

// }, {GPIO::PortG, GPIO::Pin8}),‘’’ ?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Iolo](https://discuss.px4.io/user_avatar/discuss.px4.io/iolo/32/6100_2.png) [@Iolo](https://discuss.px4.io/u/Iolo)\
**Post date:** [April 23, 2020, 1:40pm UTC](https://discuss.px4.io/t/add-a-new-external-device-on-spi-4/16322/10 "2020-04-23T13:40:07Z")

</div>

…good news 🙂 I managed to connect my sensor ADIS16475 to my Pixracer and to get data ❤ . Over all, this project is very smart implemented with one exception, in my opinion 😃 , regarding the switch between the SPI4(external) and ESP8266: why Beat Kung used, in this logic implementation (of switching between SPI&ESP), the GPIO\_8266\_GPIO2 pin? In my oppinion, this is not healthy to use a GPIO to choose between the settings of the two devices. What was the logic here with this GPIO? Why this implementation based on GPIO\_8266\_GPIO2? !!!My problem was this GPIO 😃 . I used this GPIO as an INT for my sensor!!! Also, there is no documentation regarding this. Thanks 🙂

 ![Screenshot from 2020-04-23 16-38-09](https://discuss.px4.io/uploads/default/original/2X/c/cf9fd4c1ac8811a51e53cbcb07366356f8aab588.png)
