diff Small_CPU/Src/spi.c @ 82:a6f0881074a4 kittz

+i2c analog noise filtering spi more stable
author Dmitry Romanov <kitt@bk.ru>
date Tue, 20 Nov 2018 12:08:19 +0300
parents cd298de33783
children e6abbef57475
line wrap: on
line diff
--- a/Small_CPU/Src/spi.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Small_CPU/Src/spi.c	Tue Nov 20 12:08:19 2018 +0300
@@ -82,7 +82,7 @@
 			arrayInput[i] = 0xFE;
 		if(arrayInput[i] >= 15)
 		{
-			// copy - auslöse-schwelle
+			// copy - ausl�se-schwelle
 			rework[i+1] = arrayInput[i];
 			// wieder-scharf-schalte-schwelle
 			rework[i+3+1] = arrayInput[i] - 10;
@@ -90,14 +90,14 @@
 		else
 		if(arrayInput[i] >= 10)
 		{
-			// copy - auslöse-schwelle
+			// copy - ausl�se-schwelle
 			rework[i+1] = arrayInput[i];
 			// wieder-scharf-schalte-schwelle
 			rework[i+3+1] = arrayInput[i] - 5;
 		}
 		else
 		{
-			// copy - auslöse-schwelle
+			// copy - ausl�se-schwelle
 			rework[i+1] = 7;
 			// wieder-scharf-schalte-schwelle
 			rework[i+3+1] = 6;
@@ -339,6 +339,10 @@
 
 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
 {
+	/* restart SPI */
+if(hspi == &hspi1)
+	{
+
 	global.check_sync_not_running = 0;
 	/* stop data exchange? */
 	if(global.mode == MODE_SHUTDOWN)
@@ -353,41 +357,24 @@
 	/* data consistent? */
 	if(SPI_check_header_and_footer_ok())
 	{
-		GPIO_new_DEBUG_HIGH();
+//		GPIO_new_DEBUG_HIGH(); //For debug.
 		global.dataSendToSlaveIsValid = 1;
 		global.dataSendToSlaveIsNotValidCount = 0;
 	}
 	else
 	{
-		GPIO_new_DEBUG_LOW();
+//		GPIO_new_DEBUG_LOW(); //For debug.
 		global.dataSendToSlaveIsValid = 0;
 		global.dataSendToSlaveIsNotValidCount++;
 	}
 	global.dataSendToMaster.power_on_reset = 0;
 	global.deviceDataSendToMaster.power_on_reset = 0;
-	/* no i2c or other time critical threads? */
-	if(global.dataSendToSlaveIsValid)
-	{
-		if(!global.dataSendToSlaveStopEval)
+	if(!global.dataSendToSlaveStopEval)
 		{
-			scheduleSpecial_Evaluate_DataSendToSlave();
-		}
-		else
-		{
-			global.dataSendToSlavePending = 1;
+		scheduleSpecial_Evaluate_DataSendToSlave();
 		}
-	}
-	else
-	{
-		global.dataSendToSlavePending = 0;
-	}
-	
-	/* restart SPI */
-	if(hspi == &hspi1)
-	{
-		if(global.dataSendToSlaveIsValid)
-			SPI_Start_single_TxRx_with_Master();
-	}
+	SPI_Start_single_TxRx_with_Master();
+  }
 }
 
 
@@ -415,9 +402,10 @@
 
 static void SPI_Error_Handler(void)
 {
-  while(1)
-  {
-  }
+	//The device is locks. Hard to recover.
+//  while(1)
+//  {
+//  }
 }
 
 /**