不干了!!!收

This commit is contained in:
2026-02-26 14:26:55 +08:00
parent 1fc85589c6
commit d185f63856
7 changed files with 583 additions and 114 deletions

View File

@@ -89,12 +89,21 @@ uint8_t AHT30_Init(I2C_HandleTypeDef *hi2c) {
elog_d(AHT30_TAG, "开始初始化AHT30传感器");
// 等待传感器上电稳定
osDelay(50);
osDelay(100);
// 读取初始状态
// 读取初始状态最多重试3次
uint8_t status;
if (AHT30_ReadBytes(&status, 1)) {
elog_d(AHT30_TAG, "AHT30初始状态: 0x%02X", status);
uint8_t retry = 0;
for (retry = 0; retry < 3; retry++) {
if (AHT30_ReadBytes(&status, 1)) {
elog_d(AHT30_TAG, "AHT30初始状态: 0x%02X", status);
break;
}
osDelay(10); // 重试间隔
}
if (retry >= 3) {
elog_e(AHT30_TAG, "读取AHT30初始状态失败");
return 0;
}
// 检查校准使能位,如果未启用则执行复位校准

View File

@@ -2,7 +2,7 @@
// 全局变量(零点偏移值、标定系数)
int32_t hx711_zero_offset = 0; // 零点偏移空载时的AD值
float hx711_scale = 0.002762; // 标定系数(重量/AD差值
float hx711_scale = 1.0f; // 标定系数(重量/AD差值
// #################### 基础函数 ####################
void delay_us(uint32_t us) {
@@ -13,7 +13,8 @@ void delay_us(uint32_t us) {
}
// 初始化HX711引脚SCK输出DOUT输入
void HX711_Init(void) {
// 初始化SCK引脚为低电平
HAL_GPIO_WritePin(HX711_SCK_GPIO_Port, HX711_SCK_Pin, GPIO_PIN_RESET);
}
// 读取单次AD原始数据gain增益选择
int32_t HX711_ReadData(uint8_t gain) {