feat(ads1256): 添加 EMI 防护与寄存器自恢复机制
CS 引脚加内部上拉防止干扰误触发;新增 ads1256_recover() 在检测到 寄存器被改写时重写关键配置并验证恢复。
This commit is contained in:
@@ -12,3 +12,4 @@ void ads1256_sync_wakeup(void);
|
||||
int ads1256_hwreset(void);
|
||||
int32_t ads1256_read_data(void);
|
||||
void ads1256_write_cmd(uint8_t cmd);
|
||||
int ads1256_recover(int max_retries);
|
||||
|
||||
+29
-1
@@ -179,7 +179,8 @@ int32_t ads1256_read_data(void) {
|
||||
*/
|
||||
int ads1256_init(void) {
|
||||
/* GPIO */
|
||||
gpio_pin_configure_dt(&cs_spec, GPIO_OUTPUT_INACTIVE);
|
||||
/* CS 加内部上拉:EMI 干扰时维持高电平,阻止 ADS1256 误收命令 */
|
||||
gpio_pin_configure_dt(&cs_spec, GPIO_OUTPUT_INACTIVE | GPIO_PULL_UP);
|
||||
gpio_pin_configure_dt(&reset_spec, GPIO_OUTPUT_INACTIVE);
|
||||
gpio_pin_configure_dt(&drdy_spec, GPIO_INPUT);
|
||||
|
||||
@@ -248,3 +249,30 @@ int ads1256_init(void) {
|
||||
LOG_INF("ADS1256 initialized (BUFEN=1, PGA=64, 3750SPS)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief EMI 恢复:重写关键寄存器并验证,用于马达干扰后自恢复。
|
||||
*
|
||||
* @param max_retries 最大重试次数,每次间隔 20ms。
|
||||
*
|
||||
* @retval 0 恢复成功。
|
||||
* @retval -EIO 达到最大重试次数仍未恢复。
|
||||
*/
|
||||
int ads1256_recover(int max_retries) {
|
||||
for (int i = 0; i < max_retries; i++) {
|
||||
ads1256_write_reg(REG_STATUS, 0x06);
|
||||
ads1256_write_reg(REG_ADCON, 0x07);
|
||||
ads1256_write_reg(REG_DRATE, 0xC0);
|
||||
ads1256_sync_wakeup();
|
||||
k_msleep(20);
|
||||
|
||||
uint8_t adcon = ads1256_read_reg(REG_ADCON);
|
||||
uint8_t drate = ads1256_read_reg(REG_DRATE);
|
||||
if (adcon == 0x07 && drate == 0xC0) {
|
||||
LOG_WRN("ADS1256 recovered after %d retries", i + 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
LOG_ERR("ADS1256 recovery failed after %d retries", max_retries);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user