cis001v2

Revision:
8:66caa906d24c
Parent:
6:b544e474f959
--- a/common_task.cpp	Wed Jan 06 13:35:17 2021 +0000
+++ b/common_task.cpp	Wed Feb 10 16:38:32 2021 +0000
@@ -7,17 +7,22 @@
 
 
 extern Serial pc;
+
 extern DigitalOut led3;
 extern DigitalOut led2;
+extern DigitalOut led1;
+
 extern SPI spi; // mosi, miso, sclk
 extern DigitalOut SSN;
 
-extern InterruptIn button_capture;
+extern DigitalIn button_capture;
 extern InterruptIn irq_cis;
 
 extern DigitalOut RSTN;  
 extern DigitalOut SLEEPN; 
 extern DigitalOut CAPTURE;
+extern DigitalOut CONFIG1;           
+extern DigitalOut CONFIG2;           
 
 extern uint8_t DCMI_8b_mode;
 
@@ -106,23 +111,37 @@
   * @param nonce
   * @retval void
   */
-void TASK_INIT(){ 
+void TASK_INIT_SENSOR(){ 
                       
         // Enable reset
         RSTN=0;       //0 => reset                OK             
         wait_us(5000);             
         
          //DEFAULT SIGNAL OUTPUT
+        
         // Output enable
         
+        CONFIG2=0;
+        CONFIG1=1;
+        /* config 
+        •   Pad 2’b00: version 1
+        •   Pad 2’b01: version 2 (default)
+        •   Pad 2’b10: version 3
+        •   Pad 2’b11: test mode - scan chain
+        */
+        
+        
         SLEEPN=0;     //1 => active 
-        CAPTURE=0;    //0 => no capture   
+        CAPTURE=0;    //0 => no capture  
+        SSN=1;        //1 => spi disabled 
         wait_us(5000);
         
         // Disable reset
         RSTN=1;       
         wait_us(5000);
         
+        
+        
                 
 }
 
@@ -131,9 +150,9 @@
   * @param nonce
   * @retval void
   */
-void TASK_RSTN(){
+void TASK_RSTN_SENSOR(){
         RSTN=0;
-        wait_us(2000);  
+        wait_ms(2000);  
         RSTN=1;
         wait_us(1000);
             
@@ -153,7 +172,7 @@
     
     int packet = (adr<<8 | data);
     SSN=0;
-    
+    wait_us(50);
     spi.write(packet);
     
     wait_us(50);
@@ -185,6 +204,7 @@
     //sprintf(toprint,"read at add %d -> data %d  \n\r",adr,rx_buffer);
     //myprint(toprint);
     return (int) rx_buffer;
+    
 }
 
 /**
@@ -195,30 +215,21 @@
 int TASK_TEST_SPI(void){
     
     uint8_t a;
-    int data[4]={0x55, 0xAA, 0xFF, 0x00};
+    const uint8_t size=4;
+    int data[size]={0x55, 0xAA, 0xFF, 0x00};
     int pass=0;
     int i=0;
     
     int length = sizeof(data)/sizeof(data[0]);
     
-    sprintf(toprint,"%64s","**************");
-    myprint(toprint);
-    sprintf(toprint,"%64s","PING SPI");
-    myprint(toprint);
-    sprintf(toprint,"%64s","**************");
-    myprint(toprint);
-
     for (i=0;i<length;i++){
         TASK_SPI_WRITE((int)test_add,data[i]);
         a=TASK_SPI_READ((int)test_add);
         if (a==data[i])
             pass++;
-        sprintf(toprinttemp,"write 0x%02x at 0x%02x. read 0x%02x at 0x%02x",data[i],test_add,a,test_add);
-        sprintf(toprint,"%64s",toprinttemp);
-        myprint(toprint);
     }
     
-   return (pass==4);
+   return (pass==size);
    
 }
 
@@ -230,10 +241,6 @@
     int d;
     float average;
     
-    myprint("**************\r\n");
-    myprint("ANALOG CALIB\r\n");
-    myprint("**************\r\n");
-    
     e=TASK_SPI_READ(analog_gain_add);     
     
     TASK_SPI_WRITE(mode_add,0x02);       //mode SO+calib