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

测试

相关推荐
the sun343 小时前
STM32---串口通信USART
stm32·单片机·嵌入式硬件
jacklood5 小时前
基于cubeMX的hal库STM32实现MQ2烟雾浓度检测
stm32·单片机·嵌入式硬件
qq_401700415 小时前
STM32单片机C语言
stm32·单片机
阿让啊5 小时前
单片机获取真实时间的实现方法
c语言·开发语言·arm开发·stm32·单片机·嵌入式硬件
FightingLod5 小时前
STM32版I²C相亲指南(软件硬件双修版)
c语言·stm32·单片机
狄加山6756 小时前
STM32 SysTick定时器
stm32·单片机·嵌入式硬件
Tlog嵌入式8 小时前
STM32提高篇: 蓝牙通讯
stm32·单片机·嵌入式硬件·mcu·iot
猫猫的小茶馆8 小时前
【PCB工艺】运放电路中的负反馈机制
stm32·单片机·嵌入式硬件·51单片机·pcb工艺
ye150127774559 小时前
220V转直流非隔离传感器供电电源芯片WT5105
stm32·单片机·嵌入式硬件·其他·硬件工程
海绵宝宝的月光宝盒9 小时前
[STM32] 4-1 UART与串口通信
c语言·开发语言·笔记·stm32·单片机