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:
-
Not True Daisy Chain: BNO085 doesn’t support true SPI daisy chaining where data flows through devices. You need individual CS pins.
-
SPI Bus Sharing: All sensors share MOSI, MISO, and SCK.
-
Adjust GPIO Pins: Modify the pin assignments in main.cpp to match your actual hardware connections.
-
SPI Speed: I’ve set the prescaler to 32 for reliability. You can increase speed once it’s working (prescaler 16, 8, etc.).
-
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