diff Small_CPU/Src/spi.c @ 416:bcf447646e07

Merged in Ideenmodellierer/ostc4/Improment_NVM (pull request #37) Improment NVM
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Wed, 15 Jan 2020 10:53:15 +0000
parents 2fc08a0d1ec3
children 84a4e1200726
line wrap: on
line diff
--- a/Small_CPU/Src/spi.c	Wed Jan 08 15:35:15 2020 +0100
+++ b/Small_CPU/Src/spi.c	Wed Jan 15 10:53:15 2020 +0000
@@ -24,6 +24,8 @@
 #include "global_constants.h"
 #include "spi.h"
 #include "dma.h"
+#include "batteryGasGauge.h"
+#include "pressure.h"
 
 //#include "gpio.h"
 
@@ -298,13 +300,29 @@
 }
 
 void SPI_Start_single_TxRx_with_Master(void) {
+	static uint8_t DevicedataDelayCnt = 10;
+	static uint8_t DeviceDataPending = 0;
 	uint8_t * pOutput;
 	HAL_StatusTypeDef retval;
 
-	if (global.dataSendToSlave.getDeviceDataNow) {
-		global.dataSendToSlave.getDeviceDataNow = 0;
-		pOutput = (uint8_t*) &(global.deviceDataSendToMaster);
-	} else {
+	if ((global.dataSendToSlave.getDeviceDataNow) || (DeviceDataPending))
+	{
+		if(((DevicedataDelayCnt == 0) || (((get_voltage() != 6.0) && (get_temperature() != 0.0)))))			/* devicedata complete? */
+		{
+			global.dataSendToSlave.getDeviceDataNow = 0;
+			DeviceDataPending = 0;
+			pOutput = (uint8_t*) &(global.deviceDataSendToMaster);
+		}
+		else
+		{
+			DeviceDataPending = 1;
+			DevicedataDelayCnt--;
+			pOutput = (uint8_t*) &(global.dataSendToMaster);
+		}
+
+	}
+	else
+	{
 		pOutput = (uint8_t*) &(global.dataSendToMaster);
 	}
 	retval = HAL_SPI_TransmitReceive_DMA(&hspi1, pOutput,(uint8_t*) &(global.dataSendToSlave), EXCHANGE_BUFFERSIZE);