|
@@ -174,9 +174,17 @@ static int cs1180_check_cali_offset(void){
|
|
|
cs1180_cs(0);
|
|
cs1180_cs(0);
|
|
|
spi_read_reg(0x07, (uint8_t *)&offset, 3);
|
|
spi_read_reg(0x07, (uint8_t *)&offset, 3);
|
|
|
cs1180_cs(1);
|
|
cs1180_cs(1);
|
|
|
- return offset != 0;
|
|
|
|
|
|
|
+ return (offset != 0) && (offset != 0xFFFFFF);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void cs1180_read_all_regs(void){
|
|
|
|
|
+ cs1180_save_regs(CS1180_GAIN_128X);
|
|
|
|
|
+ for (int i = 0; i < 16; i++){
|
|
|
|
|
+ sys_debug("Reg%d:0x%x\n", i, _cali_gain_regs[16 * CS1180_NOW_GAIN + i]);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
int cs1180_adc_set_gain_cali(int gain){
|
|
int cs1180_adc_set_gain_cali(int gain){
|
|
|
int count = 0;
|
|
int count = 0;
|
|
|
do {
|
|
do {
|
|
@@ -184,7 +192,6 @@ int cs1180_adc_set_gain_cali(int gain){
|
|
|
delay_us(10);
|
|
delay_us(10);
|
|
|
|
|
|
|
|
_cs1180_adc_set_gain(gain);
|
|
_cs1180_adc_set_gain(gain);
|
|
|
- delay_us(10);
|
|
|
|
|
|
|
|
|
|
if (count ++ > 50) {
|
|
if (count ++ > 50) {
|
|
|
return 0;
|
|
return 0;
|
|
@@ -254,7 +261,7 @@ int _cs1180_check_regs(int gain){
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+static int cs1180_reinit = 0;
|
|
|
//return 1: cs1180 is OK, 0: cs1180 can not work
|
|
//return 1: cs1180 is OK, 0: cs1180 can not work
|
|
|
int cs1180_adc_set_gain_online(int gain){
|
|
int cs1180_adc_set_gain_online(int gain){
|
|
|
int count = 0;
|
|
int count = 0;
|
|
@@ -266,7 +273,7 @@ int cs1180_adc_set_gain_online(int gain){
|
|
|
/*cs1180_adc_init();*/ //没有初始化成功过,或者校准没成功过
|
|
/*cs1180_adc_init();*/ //没有初始化成功过,或者校准没成功过
|
|
|
return _cs1180_ready;
|
|
return _cs1180_ready;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ cs1180_reinit ++;
|
|
|
do {
|
|
do {
|
|
|
cs1180_reset();
|
|
cs1180_reset();
|
|
|
delay_us(10);
|
|
delay_us(10);
|
|
@@ -310,7 +317,7 @@ void cs1180_adc_shutdown(void){
|
|
|
}
|
|
}
|
|
|
static int cs1180_may_error = 0;
|
|
static int cs1180_may_error = 0;
|
|
|
void cs1180_log(void){
|
|
void cs1180_log(void){
|
|
|
- sys_error("cs1180 error %d, ready %d\n", cs1180_may_error, _cs1180_ready);
|
|
|
|
|
|
|
+ sys_error("cs1180 error %d, ready %d, reinit %d\n", cs1180_may_error, _cs1180_ready, cs1180_reinit);
|
|
|
for (int i = 0; i < 16; i++){
|
|
for (int i = 0; i < 16; i++){
|
|
|
sys_debug("Reg%d:0x%x\n", i, _cali_gain_regs[16 * CS1180_NOW_GAIN + i]);
|
|
sys_debug("Reg%d:0x%x\n", i, _cali_gain_regs[16 * CS1180_NOW_GAIN + i]);
|
|
|
}
|
|
}
|