Pārlūkot izejas kodu

解决cs1180_wait_not_ready判断错误

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 gadi atpakaļ
vecāks
revīzija
5b2d7e2f9b
1 mainītis faili ar 20 papildinājumiem un 17 dzēšanām
  1. 20 17
      Application/bsp/cs1180.c

+ 20 - 17
Application/bsp/cs1180.c

@@ -87,7 +87,7 @@ static int cs1180_wait_ready(int ms){
 
 static int cs1180_wait_not_ready(int ms){
 	u64 now = shark_get_mseconds();
-	while (IS_CS1180_NOT_READY()){
+	while (!IS_CS1180_NOT_READY()){
 		if (shark_get_mseconds() - now > ms) {
 			return 0;
 		}
@@ -103,10 +103,10 @@ __attribute__((unused)) static void cs1180_self_calibrate(void)
 	cs1180_send_cmd(CS1180_CALSELF);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	cs1180_wait_ready(10);
-	cs1180_wait_not_ready(10);
+	cs1180_wait_ready(30);
+	cs1180_wait_not_ready(30);
 	delay_us(33 * 1000);
-	cs1180_wait_ready(10); //drop first data
+	cs1180_wait_ready(30); //drop first data
 }
 
 /* 对芯片的偏移误差进行纠正 */
@@ -116,10 +116,10 @@ __attribute__((unused)) static void cs1180_self_offset_calibrate(void)
 	cs1180_send_cmd(CS1180_OCALSELF);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	cs1180_wait_ready(10);
-	cs1180_wait_not_ready(10);
+	cs1180_wait_ready(30);
+	cs1180_wait_not_ready(30);
 	delay_us(33 * 1000);
-	cs1180_wait_ready(10); //drop first data
+	cs1180_wait_ready(30); //drop first data
 
 }
 
@@ -130,10 +130,10 @@ __attribute__((unused)) static void cs1180_self_gain_calibrate(void)
 	cs1180_send_cmd(CS1180_SLFGCAL);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	cs1180_wait_ready(10);
-	cs1180_wait_not_ready(10);
+	cs1180_wait_ready(30);
+	cs1180_wait_not_ready(30);
 	delay_us(33 * 1000);
-	cs1180_wait_ready(10); //drop first data
+	cs1180_wait_ready(30); //drop first data
 
 }
 
@@ -146,10 +146,10 @@ __attribute__((unused)) static void cs1180_sys_offset_calibrate(void)
 	cs1180_cs(1);
 	/* wait calibrate finished */
 	delay_us(20);
-	cs1180_wait_ready(10);
-	cs1180_wait_not_ready(10);
+	cs1180_wait_ready(30);
+	cs1180_wait_not_ready(30);
 	delay_us(33 * 1000);
-	cs1180_wait_ready(10); //drop first data	
+	cs1180_wait_ready(30); //drop first data	
 }
 
 /* 对系统的增益误差进行纠正,必须输入正满幅度的电压, SP700,SP600未提供满辐电压,故这一项不做 */
@@ -159,10 +159,10 @@ __attribute__((unused)) static void cs1180_sys_gain_calibrate(void)
 	cs1180_send_cmd(CS1180_GCALSYS);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	cs1180_wait_ready(10);
-	cs1180_wait_not_ready(10);
+	cs1180_wait_ready(30);
+	cs1180_wait_not_ready(30);
 	delay_us(33 * 1000);
-	cs1180_wait_ready(10); //drop first data
+	cs1180_wait_ready(30); //drop first data
 
 }
 
@@ -354,8 +354,10 @@ void cs1180_adc_shutdown(void){
 	_cs1180_ready = 0;
 }
 static int cs1180_may_error = 0;
+static int cs1180_ready_error = 0;
 void cs1180_log(void){
 	sys_error("cs1180 error %d-%d, ready %d, reinit %d\n", cs1180_may_error, save_reg_errors, _cs1180_ready, cs1180_reinit);
+	sys_error("cs1180 ready error %d\n", cs1180_ready_error);
 	for (int i = 0; i < 16; i++){
 		sys_debug("Reg%d:0x%x\n", i, _cali_gain_regs[16 * CS1180_NOW_GAIN + i]);
 	}
@@ -365,8 +367,9 @@ float cs1180_adc_sample(int *valide)
 	static int cs1180_low_ff_count = 0;
 	uint8_t data[3] = {0,0,0};
 	int a = 0;
-	if (cs1180_wait_ready(35) == 0) { //当drdy 为高时,不读取数据
+	if (cs1180_wait_ready(40) == 0) { //当drdy 为高时,不读取数据
 		*valide = 0;
+		cs1180_ready_error ++;
 		return 0.0f;
 	}
 #if 0