陀螺仪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;
}
设置传感器模式
获取原始数据

测试

相关推荐
youcans_9 分钟前
【嵌入式软件AI编程】12. Claude Code的基本操作
stm32·单片机·ai编程·嵌入式软件·claude code
Brilliantwxx1 小时前
【STM32】 从HAL库源码深度解析I2C(源码解析+面试题)
开发语言·stm32·单片机·嵌入式硬件·架构
老当益壮梁奶奶11 小时前
51单片机DS18B20温度传感器详解:单总线时序与C51驱动实现
笔记·stm32·单片机·嵌入式硬件·51单片机
星栖与芯12 小时前
LiteOS-M 切换汇编逐行图解(2):指令·异常机制·全景表
stm32·单片机·嵌入式硬件·harmonyos·鸿蒙系统
Brilliantwxx14 小时前
【STM32】 I2C阻塞通信实战与HAL源码(教程篇)
stm32
Brilliantwxx17 小时前
【STM32】 I2C_EEPROM_test 工程(实战篇)
开发语言·stm32·单片机·嵌入式硬件·ecmascript
youcans_17 小时前
【嵌入式软件AI编程】09. 使用VS Code调试STM32程序
stm32·mcu·ai编程·嵌入式软件·claude code
开发笔记-阿牛18 小时前
做工业报警器语音提示,CK6159A 为什么更合适?
人工智能·stm32·单片机·嵌入式硬件·音频
恶魔泡泡糖19 小时前
stm32F103C8T6标准库串口接收轮询方式1
stm32·单片机·嵌入式硬件
糖糖单片机设计20 小时前
基于STM32的远程宠物自动投喂系统
人工智能·stm32·51单片机·语音识别·智能硬件