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

测试

相关推荐
简知圈4 小时前
【04-自己画P封装,并添加已有3D封装】
笔记·stm32·单片机·学习·pcb工艺
linhhanpy8 小时前
自制虚拟机(C/C++)(二、分析引导扇区,虚拟机读二进制文件img软盘)
c语言·汇编·c++·python·stm32·操作系统
stm32发烧友13 小时前
基于 STM32 的智能电梯控制系统
stm32·单片机·嵌入式硬件
2401_8437852321 小时前
STM32 TIM定时器配置
stm32·单片机·嵌入式硬件
简知圈1 天前
06-AD向导自动创建P封装(以STM32-LQFP48格式为例)
stm32·单片机·嵌入式硬件·pcb工艺
周盛欢1 天前
STM32外设应用
stm32
2401_843785231 天前
STM32 TIM编码器接口测速
stm32·单片机·嵌入式硬件
charlie1145141912 天前
从0开始使用面对对象C语言搭建一个基于OLED的图形显示框架(基础组件实现)
c语言·驱动开发·stm32·单片机·oled·面对对象
end_SJ2 天前
初学stm32 --- FreeRTOS移植
stm32·单片机·嵌入式硬件
lhj27502008912 天前
STM32标准库移植RT-Thread nano
stm32·单片机·嵌入式硬件