      for(int i=0;i<=5;i++){
       dataout[i] =0;
     }
+   
      attachInterrupt(0,readadc,RISING);
    }
+   
 }
 void readadc(){
 
   afe.SPIEnableRead();
   for(int j=0;j<=5; j++){
+   // Serial.println(j);
    data[j] =  readmuti(0x2a+j);
   }
   afe.SPIDisableRead();

}

uint32_t readmuti(byte regAddress){
   byte temp_byte = 0;
  uint32_t reg_value = 0;
  
  digitalWrite( afe.chipSelectPin, LOW);
  
  // set address

int32_t dataout[6] = {0};
#define ave 10
int value;
char* diag_string[]={"INPSCLED","INNSCLED","INPSCGND","PDSC","PDOC","OUTNSHGND","OUTPSHGND","LEDSC","LED2OPEN","LED1OPEN","LED_ALM","PD_ALM"};
unsigned long data[6]={0};
int count = 0;

void setup() {
	Serial.begin(115200);
	afe.begin(10,3,4);   //SS,AFE_PWN,AFE_RST
Serial.println("AFE4400 Start");
        uint32_t diag_data = afe.diag();
        Serial.print("AFE4400 Diag:");
        Serial.println(diag_data,BIN);  
        int error = 0;
  for (int i = 0; i < 15; ++i)
  {
    if (bitRead(diag_data,i)==1)
    {
      Serial.println(diag_string[i]);
      error = 1;

    }

  }
  while(error){
    Serial.println("AFE4400 LED or PD connection error");
    Serial.println("Program Stopped");
   while(1){
   }
  }
  Serial.println("AFE4400 PD and LED Connection Checked");
        afe.setDefaultTiming();
        afe.setLEDCurrent(30,30); 
        afe.setGain(0x09,1,4,0,2);//AMDAC,STAGE2,GAIN,CF,RF
        /*RF 0 500K    GAIN 0  0dB      AMDAC  0 0uA ~ 10 10uA
             1 250K         1  3.5dB    CF  0 5PF
             2 100K         2  6dB          2 15PF
             3 50K          3  9.5dB        4 25PF
             4 25K          4  12dB         8 50PF  
             5 10K                          16 150PF
             6 1M                           can be added muti PF
         */
        
	afe.beginMeasure(false);//NOT PUSH-PULL
        Serial.println("==========REG_SRT========");
       	dumpreg();
        Serial.println("==========REG_END========");
        attachInterrupt(0,readadc,RISING);
  

}


void loop() {
   // readadc();
  //  delay(1000);

   if(count>=ave){
     detachInterrupt(0);
