浏览代码

fix:历史信息无法保存bug

CN\guohui27 2 年之前
父节点
当前提交
2821da94c1
共有 1 个文件被更改,包括 16 次插入15 次删除
  1. 16 15
      User project/3.BasicFunction/Source/i2c_master.c

+ 16 - 15
User project/3.BasicFunction/Source/i2c_master.c

@@ -712,7 +712,7 @@ void i2c_voHistoryWrite2EE(const I2C_TX_COF *coef, I2C_TX_OUT *out)
 	ubReTX2 = 2;
 	ubReTX2 = 2;
 #endif
 #endif
 
 
-	ubSlaveAddr = I2C_SLAVEADDR_BLOCK3;
+    ubSlaveAddr = I2C_SLAVEADDR_BLOCK3;
     ubWriteAddr = 0x00;
     ubWriteAddr = 0x00;
 
 
     while (ubReTX2 != 0)
     while (ubReTX2 != 0)
@@ -807,11 +807,10 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
    
    
     UBYTE i2c_timeout_flag = 0;
     UBYTE i2c_timeout_flag = 0;
     UBYTE *p_buffer;
     UBYTE *p_buffer;
+    
      while(ubRdCnt != 0)
      while(ubRdCnt != 0)
      {
      {
     	 ubRdCnt--;
     	 ubRdCnt--;
-        /* enable acknowledge */
-        i2c_ack_config(I2C0, I2C_ACK_ENABLE);
 
 
         if (ubRdCnt == 1)
         if (ubRdCnt == 1)
         {
         {
@@ -834,6 +833,9 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
         	//do nothing
         	//do nothing
         }
         }
         
         
+        /* enable acknowledge */
+        i2c_ack_config(I2C0, I2C_ACK_ENABLE);
+        
         while(i2c_timeout_flag ==0)
         while(i2c_timeout_flag ==0)
         {
         {
             switch(state) 
             switch(state) 
@@ -865,7 +867,6 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                         i2c_bus_reset();
                         i2c_bus_reset();
                         timeout = 0;
                         timeout = 0;
                         state = (UBYTE)I2C_START;
                         state = (UBYTE)I2C_START;
-                       
                     }
                     }
                 } 
                 } 
                 else 
                 else 
@@ -900,7 +901,6 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                     timeout = 0;
                     timeout = 0;
                     state = (UBYTE)I2C_START;
                     state = (UBYTE)I2C_START;
                     read_cycle = 0;
                     read_cycle = 0;
-                    
                 }
                 }
                 break;
                 break;
             case I2C_CLEAR_ADDRESS_FLAG:
             case I2C_CLEAR_ADDRESS_FLAG:
@@ -914,12 +914,12 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                     i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
                     i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
                     timeout = 0;
                     timeout = 0;
                     state = (UBYTE)I2C_TRANSMIT_DATA;
                     state = (UBYTE)I2C_TRANSMIT_DATA;
-                } else 
+                } 
+                else 
                 {
                 {
                     timeout = 0;
                     timeout = 0;
                     state = (UBYTE)I2C_START;
                     state = (UBYTE)I2C_START;
-                    read_cycle = 0;
-                    
+                    read_cycle = 0;   
                 }
                 }
                 break;
                 break;
             case I2C_TRANSMIT_DATA:
             case I2C_TRANSMIT_DATA:
@@ -940,8 +940,7 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                     {
                     {
                         timeout = 0;
                         timeout = 0;
                         state = (UBYTE)I2C_START;
                         state = (UBYTE)I2C_START;
-                        read_cycle = 0;
-                        
+                        read_cycle = 0;    
                     }
                     }
                     /* wait until BTC bit is set */
                     /* wait until BTC bit is set */
                     while((i2c_flag_get(I2C0, I2C_FLAG_BTC) == 0) && (timeout < I2C_SHORT_TIMEOUT))
                     while((i2c_flag_get(I2C0, I2C_FLAG_BTC) == 0) && (timeout < I2C_SHORT_TIMEOUT))
@@ -953,12 +952,12 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                         timeout = 0;
                         timeout = 0;
                         state = (UBYTE)I2C_START;
                         state = (UBYTE)I2C_START;
                         read_cycle++;
                         read_cycle++;
-                    } else 
+                    }
+                    else 
                     {
                     {
                         timeout = 0;
                         timeout = 0;
                         state = (UBYTE)I2C_START;
                         state = (UBYTE)I2C_START;
                         read_cycle = 0;
                         read_cycle = 0;
-                        
                     }
                     }
                 } 
                 } 
                 else 
                 else 
@@ -986,10 +985,10 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                     } 
                     } 
                     else 
                     else 
                     {  /* more than one byte master reception procedure (DMA) */                   
                     {  /* more than one byte master reception procedure (DMA) */                   
-                        dma_transfer_number_config(DMA0, DMA_CH6, ubRdNBytes);
-                        
+                      
+                        dma_transfer_number_config(DMA0, DMA_CH6, ubRdNBytes);        
                         DMA_CH6MADDR(DMA0) = (ULONG)p_buffer;
                         DMA_CH6MADDR(DMA0) = (ULONG)p_buffer;
-                    
+                      
                         i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON);
                         i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON);
                         /* enable I2C0 DMA */
                         /* enable I2C0 DMA */
                         i2c_dma_config(I2C0, I2C_DMA_ON);
                         i2c_dma_config(I2C0, I2C_DMA_ON);
@@ -1013,11 +1012,13 @@ void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28
                 {
                 {
                     timeout++;
                     timeout++;
                 }
                 }
+
                 if(timeout < I2C_SHORT_TIMEOUT)
                 if(timeout < I2C_SHORT_TIMEOUT)
                 {
                 {
                     timeout = 0;                 
                     timeout = 0;                 
                     i2c_timeout_flag = 1;
                     i2c_timeout_flag = 1;
                     state = (UBYTE)I2C_START;
                     state = (UBYTE)I2C_START;
+                    read_cycle = 0;
                    
                    
                     /* disable DMA0 CH6 */
                     /* disable DMA0 CH6 */
                     dma_channel_disable(DMA0, DMA_CH6);
                     dma_channel_disable(DMA0, DMA_CH6);