2025-11-15 20:04:37 +08:00

48 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef AD7606_H
#define AD7606_H
#include <Arduino.h>
#include <SPI.h>
// 可按需修改为你的实际接线。若 OS 引脚已硬连到 GND/3V3可将其保持为 -1不配置
namespace ad7606 {
// 数据/控制引脚
static const int PIN_AD_MISO = 8; // DOUTA -> ESP32 MISO
static const int PIN_AD_CS = 39; // CS_N
static const int PIN_AD_CONVST = 13; // CONVSTCO-A/CO-B 共用)
static const int PIN_AD_RESET = 40; // RESET
static const int PIN_AD_BUSY = 38; // BUSY
// 可选:过采样和模式引脚(-1 表示不配置/已硬件固定)
static const int PIN_AD_OS0 = -1;
static const int PIN_AD_OS1 = -1;
static const int PIN_AD_OS2 = -1;
static const int PIN_AD_SER = -1; // SER=1 串行模式(若已焊 3.3V,可 -1
static const int PIN_AD_STBY = -1; // STBY=1 正常工作(若已焊 3.3V,可 -1
// 量程:用于将 16-bit 原码转换为电压(缺省 ±10V
static constexpr float AD_FS_VOLTS = 5.0f; // 根据硬件 RANGE 引脚实际设置改成 5.0/2.5 等
// 初始化(与 TFT 共用 SPI外部需已调用 SPI.begin 并指定 MISO=SENSOR_DOUT
void init();
// 触发并读取 8 路原始数据(阻塞等待 BUSY 变低)
void readAll(int16_t* data8);
// 读取 CH0 原始码
inline int16_t readCH0() {
int16_t tmp[8];
readAll(tmp);
return tmp[0];
}
// 原码转电压,范围 ±AD_FS_VOLTS
inline float codeToVolts(int16_t code) {
return (static_cast<float>(code) / 32768.0f) * AD_FS_VOLTS;
}
} // namespace ad7606
#endif