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

测试

相关推荐
不能跑的代码不是好代码7 小时前
STM32窗口看门狗(WWDG)知识点及标准库使用指南
stm32·单片机·嵌入式硬件
bingquan33337 小时前
在 Ghidra 中分析STM32裸机固件
stm32·单片机·嵌入式硬件
羽获飞7 小时前
从零开始学嵌入式之STM32——11.STM32---USART串行通讯
stm32·单片机·嵌入式硬件
宵时待雨9 小时前
STM32笔记归纳9:定时器
笔记·stm32·单片机·嵌入式硬件
逐步前行9 小时前
STM32_新建工程(寄存器版)
stm32·单片机·嵌入式硬件
bai5459369 小时前
STM32 CubeIDE 通过PWM占空比控制舵机角度
stm32·单片机·嵌入式硬件
逐步前行16 小时前
STM32_标准库结构
stm32·单片机·嵌入式硬件
Hello_Embed16 小时前
libmodbus STM32 主机实验(USB 串口版)
笔记·stm32·学习·嵌入式·freertos·modbus
不做无法实现的梦~16 小时前
PX4各个模块的作用(3)
linux·stm32·嵌入式硬件·机器人·自动驾驶
不能跑的代码不是好代码17 小时前
STM32独立看门狗(IWDG)知识点及标准库使用指南
stm32·嵌入式硬件