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

测试

相关推荐
阿容1234564 小时前
stm32两轮平衡小车 -04
stm32·嵌入式硬件
silno7 小时前
图解 STM32 USB CDC虚拟串口 的实现
stm32·单片机·stm32f103c8t6·cdc虚拟串口
一枝小雨10 小时前
7 App代码转AES加密文件生成步骤
stm32·单片机·嵌入式·aes·ota·bootloader·加密升级
云山工作室12 小时前
基于ZigBee的温室智能控制系统设计(论文+源码)
stm32·单片机·嵌入式硬件·物联网·课程设计
IT_阿水12 小时前
基于STM32的智慧物联网系统板
stm32·物联网·perl
云山工作室12 小时前
血糖浓度测试仪设计(论文+源码)
stm32·单片机·嵌入式硬件·毕业设计·毕设
雨疏风骤124013 小时前
【FreeRTOS】任务、任务状态
开发语言·stm32·c#·rtos
Darken0314 小时前
基于 STM32 ——GPIO输入
stm32·单片机·嵌入式硬件·gpio
影阴14 小时前
stm32 硬件i2c + hal库
stm32·单片机·嵌入式硬件
阿拉斯攀登14 小时前
在STM32上使用FreeRTOS
stm32·单片机·嵌入式硬件