01-14-2020 04:28 AM
Hi,
My team is in the process of building a wearable product, and are currently testing using the BHI160 Sensor Hub with the nRF52832 Adafruit Feather. For some contextual information between the sensor hub and the Adafruit nRF boards, respectively, both VDD and VDDIO are tied to 3.3V, GND is tied to GND, SDA is tied to SDA, SCL is tied to SCL, and INTC/IO7 is tied to pin 7. In addition, the appropriate 2.2 KOhm resistors are being used as pullups on the I2C bus.
We are having trouble running the orientation.ino sample code provided in the library. The application code being tested can be found below. You will notice that there is one change made to the original "orientation.ino" example found in the library. The firmware hex file was changed to "Bosch_PCB_7183_di01_BMI160-7183_di01.2.1.10836_170103.h". This was because we were getting the following error message when using the original one: "Error code: (-22). RAM-Patch Mismatch".
"""""""""""""""""""""""""""""""
#include <Wire.h>
#include "bhy.h"
#include "Bosch_PCB_7183_di01_BMI160-7183_di01.2.1.10836_170103.h"
#define BHY_INT_PIN 7
BHYSensor bhi160;
volatile bool intrToggled = false;
bool newOrientationData = false;
float heading, roll, pitch;
uint8_t status;
bool checkSensorStatus(void);
void bhyInterruptHandler(void)
{
intrToggled = true;
}
void waitForBhyInterrupt(void)
{
while (!intrToggled)
;
intrToggled = false;
}
void orientationHandler(bhyVector data, bhyVirtualSensor type)
{
heading = data.x;
roll = data.z;
pitch = data.y;
status = data.status;
newOrientationData = true;
}
void setup()
{
Serial.begin(115200);
Wire.begin();
if (Serial)
{
Serial.println("Serial working");
}
attachInterrupt(BHY_INT_PIN, bhyInterruptHandler, RISING);
bhi160.begin(BHY_I2C_ADDR);
/* Check to see if something went wrong. */
if (!checkSensorStatus())
return;
Serial.println("Sensor found over I2C! Product ID: 0x" + String(bhi160.productId, HEX));
Serial.println("Uploading Firmware.");
bhi160.loadFirmware(bhy1_fw);
if (!checkSensorStatus())
return;
intrToggled = false; /* Clear interrupt status received during firmware upload */
waitForBhyInterrupt(); /* Wait for meta events from boot up */
Serial.println("Firmware booted");
/* Install a metaevent callback handler and a timestamp callback handler here if required before the first run */
bhi160.run(); /* The first run processes all boot events */
/* Install a vector callback function to process the data received from the wake up Orientation sensor */
if (bhi160.installSensorCallback(BHY_VS_ORIENTATION, true, orientationHandler))
{
checkSensorStatus();
return;
}
else
Serial.println("Orientation callback installed");
/* Enable the Orientation virtual sensor that gives you the heading, roll, pitch
based of data from the accelerometer, gyroscope and magnetometer.
The sensor is set into wake up mode so as to interrupt the host when a new sample is available
Additionally, the FIFO buffer of the sensor is flushed for all previous data
The maximum report latency of the sensor sample, the sensitivity and the dynamic range
are set to 0
*/
if (bhi160.configVirtualSensor(BHY_VS_ORIENTATION, true, BHY_FLUSH_ALL, 200, 0, 0, 0))
{
Serial.println("Failed to enable virtual sensor (" + bhi160.getSensorName(
BHY_VS_ORIENTATION) + "). Loaded firmware may not support requested sensor id.");
}
else
Serial.println(bhi160.getSensorName(BHY_VS_ORIENTATION) + " virtual sensor enabled");
}
void loop()
{
if (intrToggled)
{
intrToggled = false;
bhi160.run();
checkSensorStatus();
if (newOrientationData)
{
/* Can also be viewed using the plotter */
Serial.println(String(heading) + "," + String(pitch) + "," + String(roll) + "," + String(status));
newOrientationData = false;
}
}
}
bool checkSensorStatus(void)
{
if (bhi160.status == BHY_OK)
return true;
if (bhi160.status < BHY_OK) /* All error codes are negative */
{
Serial.println("Error code: (" + String(bhi160.status) + "). " + bhi160.getErrorString(bhi160.status));
return false; /* Something has gone wrong */
}
else /* All warning codes are positive */
{
Serial.println("Warning code: (" + String(bhi160.status) + ").");
return true;
}
return true;
}
"""""""""""""""""""""""""""""""
The sketch compiles and runs but does not return any sensor data. We get the following Serial monitor output (notice the warning code 1):
Serial working
Sensor found over I2C! Product ID: 0x83
Uploading Firmware.
Firmware booted
Orientation callback installed
Orientation (Non Wake-up) virtual sensor enabled
Warning code: (1)
One observation that we have made is that the warning code (1) is because of line 2088 in bhy.cpp, where the acknowledgement bit is being read as 0x80 due to an invalid parameter number (227) being written. According to the documentation, only numbers between 1-127 (for Parameter Page 3) are valid.
Another observation we made was that the "orientationHandler" ISR is never being called, and therefore, newOrientationData is never being set to true. We are not too sure of what is happening in the following vector callback function: "bhi160.installSensorCallback(BHY_VS_ORIENTATION, true, orientationHandler)". We believe that there is something weird going on in its function definition located in the bhy.cpp file.
We are not sure what is going on here, and any help would be greatly appreciated.
01-29-2020 01:27 PM