Skip to content

MAX32666 and BMI160 communication issues with I2C #1487

@obones

Description

@obones

Hello,

I'm using the publicly released version of MSDK to write code for the MAX32666FTHR board, trying to use the integrated BMI160 IMU
While most things work properly, I found that I had an infinite loop when trying to read all 6 accelerometer registers in one read call. Basically, the first read works, but any subsequent call ends up in an endless loop inside i2c_reva.c
Looking at the history of files here, I found out that commit 1b95b29 is the solution to this endless loop and so I applied the changes locally.
In an effort to keep the file up to date, I also applied changes from other commits, but I found out that b63a90d broke communication in my case. Indeed, with this commit, the first call works, but any subsequent call receives a E_BUSY error. If I simply remove the changes from that commit and keep the previously mentioned one, everything is back to a working, situation.

Here is the code that reads the 6 registers at once:

void loop()
{
    uint8_t buffer[6] = {};

    _i2c_req_t req;
    req.addr = 0b1101000;
    req.i2c = MXC_I2C0_BUS0;
    req.tx_buf = buffer;
    req.tx_len = 1;
    req.rx_buf = buffer;
    req.rx_len = 6;

    buffer[0] = 0x12; // first accelerometer register

    int err = MXC_I2C_MasterTransaction(&req);
    switch (err)
    {
        case E_NO_ERROR:
            break;
        case E_BUSY:
            printf("x");
            return;
        default:
            printf("TraceActivity::loop(): I2C failed: %d.\n", err);
            return;
    }

    ax = ((int16_t)buffer[1]) << 8 | buffer[0];
    ay = ((int16_t)buffer[3]) << 8 | buffer[2];
    az = ((int16_t)buffer[5]) << 8 | buffer[4];

    printf("ax: %d, ay: %d, az: %d\n", ax, ay, az);
}

I'm not sure what the solution would be, but in my case, reverting b63a90d would be my recommendation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions