Multiple BNO085's

I wanted to use multiple BNO085’s with the STM32 using SPI Daisy Chain. I’d found a GitHub repo of a modified Sparkfun Arduino BNO080 library, modified to work with the STM32- The repo. I tried to modify this library to work with multiple BNO’s but I’m unable to get it working.

Changes made:

  • Created a structure to share the variables between both of the IMU’s
  • Created instances of both the IMU’s
  • Passed functions with the structure parameters so that the functions are called separately for both the IMU’s
  • Separate CS Pins and INT Pins used for the two IMU’s

Issue’s faced:

I get the default quaternion values i.e., 0,180,360. Unable to get live values.

This is my repo, My repo

I would appreciate any help on this.

That means nothing to forum members, other than you are unhappy with the results.

Please describe the problems in detail. Explain what you tried, what you expected to happen, what happened instead, and what you did to debug the issues.

Without more detailed info I tossed this to claude.ai to attempt deciphering, it had a few preliminary ideas:

1. Incorrect Chip Select Logic in SPIReadWrite()

In your BNO080.cpp, the SPIReadWrite() function still only uses sensorCSPin:

void BNO080::SPIReadWrite(uint8_t *pTxData, uint8_t *pRxData, uint16_t size, uint8_t _csPin)
{
    HAL_GPIO_WritePin(sensorCSPort, sensorCSPin, GPIO_PIN_RESET); // Wrong pin!
    HAL_SPI_TransmitReceive(spiPort, pTxData, pRxData, size, 5000);
    HAL_GPIO_WritePin(sensorCSPort, sensorCSPin, GPIO_PIN_SET);   // Wrong pin!
}

You’re passing _csPin as a parameter but never using it! It should use the passed _csPin parameter.

2. CS Pin Management Issues

The class stores both sensorCSPin and has functions with _csPin parameters, but they’re not coordinated properly. When you call functions like receivePacket(), they call SPIReadWrite() without a CS pin parameter.

3. Initialization Order

In main.cpp, you’re calling imu1.begin() and imu2.begin() sequentially, but the BNO085 needs proper reset timing and may need delays between initializations.

Solution

Here’s a corrected version of your library. Now here’s an updated main.cpp example showing proper usage with multiple sensors…also see updated header code and BNO080.cpp

Key Changes Made:

1. Fixed CS Pin Usage

  • Removed the _csPin parameter from SPIReadWrite()
  • The class now stores its own CS pin in sensorCSPin during begin()
  • Each instance uses its own CS pin automatically

2. Simplified begin() Function

  • Each BNO080 instance stores its own CS, INT, and RST pins
  • No need to pass CS pin on every function call

3. Proper Initialization

  • Added delays between sensor initializations (200ms)
  • Each sensor gets its own reset sequence

Hardware Connection Guide:

STM32F4         BNO085 #1       BNO085 #2
-------         ---------       ---------
SPI1_SCK   -->  SCK        -->  SCK        (shared)
SPI1_MISO  <--  MISO       <--  MISO       (shared)
SPI1_MOSI  -->  MOSI       -->  MOSI       (shared)

PB6        -->  CS              (individual)
PB7                       -->  CS          (individual)

PC7        <--  INT             (individual)
PC8                       <--  INT         (individual)

PA9        -->  RST             (individual)
PA10                      -->  RST         (individual)

3.3V       -->  VCC        -->  VCC
GND        -->  GND        -->  GND

Important Notes:

  1. Not True Daisy Chain: BNO085 doesn’t support true SPI daisy chaining where data flows through devices. You need individual CS pins.

  2. SPI Bus Sharing: All sensors share MOSI, MISO, and SCK.

  3. Adjust GPIO Pins: Modify the pin assignments in main.cpp to match your actual hardware connections.

  4. SPI Speed: I’ve set the prescaler to 32 for reliability. You can increase speed once it’s working (prescaler 16, 8, etc.).

  5. Pull-up Resistors: Make sure INT pins have pull-up resistors (either internal via software or external 4.7k-10k ohm).

Try this updated code and let me know if you’re still having issues! If it doesn’t work, please share:

  • What specific behavior you’re seeing (timeouts, wrong data, no response, etc.)
  • Any error messages
  • Which sensors (if any) are working