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

测试

相关推荐
boneStudent10 小时前
Day29:I2C 高级应用
stm32·单片机·嵌入式硬件
@good_good_study11 小时前
STM32 I2C配置函数及实验
stm32·单片机
芯联智造12 小时前
【stm32简单外设篇】- 28BYJ-48 步进电机(配 ULN2003 驱动板)
c语言·stm32·单片机·嵌入式硬件
星期天213 小时前
1.4光敏传感器控制蜂鸣器
stm32·单片机·嵌入式硬件·江科大
沐欣工作室_lvyiyi14 小时前
基于无线互联的电源健康监测与控制系统设计(论文+源码)
stm32·单片机·毕业设计·电源健康监测
@good_good_study15 小时前
STM32 ADC单通道采样函数及实验
stm32·单片机
田甲15 小时前
【STM32】基于TPS61165芯片的LED驱动电路
stm32·单片机·嵌入式硬件
d111111111d15 小时前
STM32得中断服务函数,为什么不能有返回值
笔记·stm32·单片机·嵌入式硬件·学习
时光の尘15 小时前
嵌入式面试八股文(十九)·裸机开发与RTOS开发的区别
linux·stm32·单片机·iic·rtos·spi
d111111111d16 小时前
连续形式PID和离散PID-详情学习-江科大(学习笔记)
笔记·stm32·单片机·嵌入式硬件·学习