You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Raspberry Pi Pico C/C++ SDK通过I2C读取BNO085数据异常求助

Raspberry Pi Pico W读取BNO085传感器数据异常问题

我正尝试使用C/C++ SDK在Raspberry Pi Pico W上读取BNO085传感器数据(因时序限制无法使用Circuit Python),采用I2C通信方式。编写了基础C程序读取原始数据,但输出结果不符合预期:程序发送和接收数据的返回值显示传输正常,但接收的首字节应为报告ID 0XF8,实际输出却不是。

相关代码

#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "pico/binary_info.h"

// 定义Pico W的I2C实例和引脚
#define I2C_PORT i2c0
#define SDA_PIN 4
#define SCL_PIN 5

static int bno_addr = 0x4A;

// 主函数
int main() {
    // 初始化标准输出
    stdio_init_all();
    sleep_ms(2000); // 等待USB串口连接建立

    // 初始化I2C
    i2c_init(I2C_PORT, 100 * 1000); // 100kHz速率初始化
    gpio_set_function(SDA_PIN, GPIO_FUNC_I2C);
    gpio_set_function(SCL_PIN, GPIO_FUNC_I2C);
    gpio_pull_up(SDA_PIN);
    gpio_pull_up(SCL_PIN);

    uint8_t send_product_ID[2] = {0xF9, 0x00};
    printf("%d\n", i2c_write_blocking(I2C_PORT, bno_addr, send_product_ID, sizeof(send_product_ID), false));
    sleep_ms(100);

    uint8_t recieveArrp[16];
    printf("%d\n", i2c_read_blocking(I2C_PORT, bno_addr, recieveArrp, 16, true));
    for(int i = 0; i < 16; i++) {
        printf("\n%02x", recieveArrp[i]);
    }
    printf("\n");
    return 0;
}

输出结果

2
16

14
01
00
00
00
01
04
00
00
00
00
80
06
31
2e
30

内容的提问来源于stack exchange,提问作者Adan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 05:33:19