Просмотр исходного кода

cs1180 加入debug信息

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 лет назад
Родитель
Сommit
882cadd563
3 измененных файлов с 15 добавлено и 6 удалено
  1. 2 1
      Application/app/pc_message.c
  2. 12 5
      Application/bsp/cs1180.c
  3. 1 0
      Application/bsp/cs1180.h

+ 2 - 1
Application/app/pc_message.c

@@ -1,7 +1,7 @@
 #include "pc_message.h"
 #include "pcba_test.h"
 #include "app/sox/measure.h"
-
+#include "bsp/cs1180.h"
 int process_pc_message(can_frame_t *frame, int len){
 	int processed = 0;
 	if (frame->key == CAN_KEY_PCBA_TEST) {
@@ -13,6 +13,7 @@ int process_pc_message(can_frame_t *frame, int len){
 		uint8_t result = 0;
 		if (len != sizeof(cali_cmd_t)) {
 			current_calibrate();//just for debug
+			cs1180_read_all_regs();
 			result = 1;
 		}else {
 			cali_cmd_t * cmd = (cali_cmd_t *)frame->data;

+ 12 - 5
Application/bsp/cs1180.c

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

+ 1 - 0
Application/bsp/cs1180.h

@@ -18,6 +18,7 @@ void cs1180_sys_offset_calibrate(void);
 float cs1180_adc_sample(int *valide);
 int cs1180_change_gain(int current);
 void cs1180_log(void);
+void cs1180_read_all_regs(void);
 
 #endif /* _CS1180_H__ */