陀螺仪BMI323驱动开发测试(基于HAL库SPI通信)

参考资料

编写代码

读取芯片ID
c 复制代码
void BMI160_Init(void)
{
    uint16_t chipID = BMI323_read(BMI160_REG_CHIP_ID);
    debug("BMI323芯片ID为0x%x;", chipID);
    if (chipID != 0x43)
    {
        debug("未检测到BMI323;");
    }
    else
        debug("检测到陀螺仪BMI323;");
    u8 buf_config[2] = {0xC9, 0x70};
    BMI160_WriteBytes(0x21, buf_config, 2);
    uint16_t state = BMI323_read(0x02);
    debug("BMI323传感器状态为0x%x;", state);
    prev_yaw = agv_currentAngle.f;
}
uint16_t BMI323_read(uint8_t reg)
{
    uint16_t value;
    HAL_GPIO_WritePin(BMI160_CS_GPIO_Port, BMI160_CS_Pin, GPIO_PIN_RESET);
    SPI_TransferByte(reg | 0x80);
    value = SPI_TransferByte(0) << 8; /* 读取高8位字节 */
    value |= SPI_TransferByte(0);     /* 读取低8位字节 */
    HAL_GPIO_WritePin(BMI160_CS_GPIO_Port, BMI160_CS_Pin, GPIO_PIN_SET);
    return value;
}
uint8_t SPI_TransferByte(uint8_t data)
{
    uint8_t rxData;
    HAL_SPI_TransmitReceive(&hspi2, &data, &rxData, 1, HAL_MAX_DELAY);
    return rxData;
}
设置传感器模式
获取原始数据

测试

相关推荐
玄芯散人10 小时前
【元婴·100】STM32启动流程:从上电到main()经历了什么
stm32·单片机·嵌入式硬件
科芯创展13 小时前
XZ5129:单节锂电池供电36V升压LED恒流驱动芯片设计解析
stm32·单片机·嵌入式硬件
羊羊一洋14 小时前
ROM&RAM
c语言·stm32·学习
创界工坊工作室15 小时前
41-基于STC89C52的避障循迹小车
stm32·单片机·嵌入式硬件·51单片机·proteus
en.en..15 小时前
第一篇:位域打包:看懂 I2C 地址左移的底层逻辑
stm32·嵌入式·位运算·i2c·底层驱动
Zw-awa16 小时前
工程师的词典:缺省值、鲁棒性,和那些名不副实的怪词
stm32
youcans_16 小时前
【嵌入式软件AI编程】21. 整理通用提示词模板
stm32·单片机·嵌入式·ai编程
zhangzhangkeji16 小时前
stm32, HAL 库,定时器
stm32
新晨单片机设计17 小时前
S025F-STM32蓝牙智能手环(心率、血氧、体温、计步)【Proteus仿真+Keil程序+原理图】
stm32·嵌入式硬件·proteus·蓝牙智能手环
创界工坊工作室19 小时前
49-基于单片机的火警报警器设计
stm32·单片机·嵌入式硬件·51单片机·proteus