Add a new external device on SPI 4

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::bus::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.

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

@bkueng any idea what to try out?

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

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?

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 :slightly_smiling_face:

So is it working?

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

…no, it’s not working :frowning_face: . 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. :slight_smile: Thanks :slight_smile:

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.

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

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?

.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 , 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: :bus::SPI4, {

// // no devices

// TODO: if enabled, remove GPIO_VDD_3V3_SENSORS4_EN from board_config.h

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

Thanks :slight_smile:

…good news :slight_smile: I managed to connect my sensor ADIS16475 to my Pixracer and to get data :heart: . Over all, this project is very smart implemented with one exception, in my opinion :smiley: , 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 :smiley: . I used this GPIO as an INT for my sensor!!! Also, there is no documentation regarding this. Thanks :slight_smile: