_BV not declared on MKR WiFI1010

Hi everyone,
I’m trying to use one of the MPU6050 examples provided in Jeff Rowberg’s i2c library, but when I try to compile the code for the MKR Wifi1010 board, it gives me the following error: ‘_BV’ was not declared in this scope (on line 287). If I change board types back to Arduino/Genuino Uno, then the same code compiles fine. From my digging into this error I found that the _BV is a macro that may or may not be exposed on various boards. Is there a way for me to get around this for the MKR boards?

For reference, here’s the snippet in the .ino file which throws the error:

// get current FIFO count
fifoCount = mpu.getFIFOCount();
if(fifoCount < packetSize){
    //Lets go back and wait for another interrupt. We shouldn't be here, we got an interrupt from another event
    // This is blocking so don't do it   while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
}
// check for overflow (this should never happen unless our code is too inefficient)
else if ((mpuIntStatus & _BV(MPU6050_INTERRUPT_FIFO_OFLOW_BIT)) || fifoCount >= 1024) {
    // reset so we can continue cleanly
    mpu.resetFIFO();
    Serial.println(F("FIFO overflow!"));

I’m following up on my initial question because I may have found a solution (however, I was wondering if anyone could help explain why this works. From a different forum post, the poster says that the _BV() macro is an AVR specific thing and obviously the MKR WiFi board is a MO processor. He goes on to say that the equivalent of _BV(i) would be something like 0x01 << i. When I update my code this does appear to appease the compiler… but can someone explain in a little more detail what the _BV() macro and/or 0x01<<i is supposed to actually do?

but can someone explain in a little more detail what the _BV() macro and/or 0x01<<i is supposed to actually do?

In your case

if ((mpuIntStatus & _BV(MPU6050_INTERRUPT_FIFO_OFLOW_BIT))

from the library

#define MPU6050_INTERRUPT_FIFO_OFLOW_BIT    4

The code is acting to determine if there is an overflow condition. W

Where does mpuIntStatus come from?

It appears to be a value that can evidently indicate several interrupt conditions, and the code is testing to see if bit 4 is set.

The mpuIntStatus variable is a uint8_t which gets set in the setup function like this:

mpuIntStatus = mpu.getIntStatus();

When I print this value to the serial monitor, the value appears to be a 1.

The mpuIntStatus variable is a uint8_t which gets set in the setup function like this:
Code: [Select]

mpuIntStatus = mpu.getIntStatus();

When I print this value to the serial monitor, the value appears to be a 1.

Take a look at the mpu6050 register map. https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf

Bit 4 of Register 58 (Register 58 – Interrupt StatusINT_STATUS) is FIFO_OFLOW_INT This bit automatically sets to 1 when a FIFO buffer overflow interrupt has been generated.The bit clears to 0 after the register has been read.

When you do not have an overflow condition and the value is you see is 1, you are seeing a data ready interrupt condition.

So, I finally got everything working correctly. The issue I found was that I was using the wrong interrupt pin. The code typically uses DPin2 but this is assuming most people are using an Arduino Uno (or at least an AVR varient). However, the MKR boards don't use DPin2 for external interrupts (as I found out). So, once I switched this to one of the correct pins (I chose DPin4), then the MKR board started streaming the data from the IMU as expected. Thanks again for your help.