comparison Small_CPU/Src/spi.c @ 408:2fc08a0d1ec3 Improment_NVM

Bugfix invalid voltage / temperatur after coldstart: In case of a cold start (complete power on / off) the RTE could send devie data before values like voltage or temperature have been measured for the first time. As result the device history data was set to it limits causing a minimal voltage of 2V to be displayed in history memory. Workaround for voltage is to initialize it to 6V at startup but for temperature a default value having no impact to the history memory is not possible
author ideenmodellierer
date Sun, 12 Jan 2020 19:50:14 +0100
parents 580822b5d3d1
children 84a4e1200726
comparison
equal deleted inserted replaced
407:b11e50415982 408:2fc08a0d1ec3
22 /* Includes ------------------------------------------------------------------*/ 22 /* Includes ------------------------------------------------------------------*/
23 23
24 #include "global_constants.h" 24 #include "global_constants.h"
25 #include "spi.h" 25 #include "spi.h"
26 #include "dma.h" 26 #include "dma.h"
27 #include "batteryGasGauge.h"
28 #include "pressure.h"
27 29
28 //#include "gpio.h" 30 //#include "gpio.h"
29 31
30 /* USER CODE BEGIN 0 */ 32 /* USER CODE BEGIN 0 */
31 #include "scheduler.h" 33 #include "scheduler.h"
296 HAL_Delay(50); 298 HAL_Delay(50);
297 #endif 299 #endif
298 } 300 }
299 301
300 void SPI_Start_single_TxRx_with_Master(void) { 302 void SPI_Start_single_TxRx_with_Master(void) {
303 static uint8_t DevicedataDelayCnt = 10;
304 static uint8_t DeviceDataPending = 0;
301 uint8_t * pOutput; 305 uint8_t * pOutput;
302 HAL_StatusTypeDef retval; 306 HAL_StatusTypeDef retval;
303 307
304 if (global.dataSendToSlave.getDeviceDataNow) { 308 if ((global.dataSendToSlave.getDeviceDataNow) || (DeviceDataPending))
305 global.dataSendToSlave.getDeviceDataNow = 0; 309 {
306 pOutput = (uint8_t*) &(global.deviceDataSendToMaster); 310 if(((DevicedataDelayCnt == 0) || (((get_voltage() != 6.0) && (get_temperature() != 0.0))))) /* devicedata complete? */
307 } else { 311 {
312 global.dataSendToSlave.getDeviceDataNow = 0;
313 DeviceDataPending = 0;
314 pOutput = (uint8_t*) &(global.deviceDataSendToMaster);
315 }
316 else
317 {
318 DeviceDataPending = 1;
319 DevicedataDelayCnt--;
320 pOutput = (uint8_t*) &(global.dataSendToMaster);
321 }
322
323 }
324 else
325 {
308 pOutput = (uint8_t*) &(global.dataSendToMaster); 326 pOutput = (uint8_t*) &(global.dataSendToMaster);
309 } 327 }
310 retval = HAL_SPI_TransmitReceive_DMA(&hspi1, pOutput,(uint8_t*) &(global.dataSendToSlave), EXCHANGE_BUFFERSIZE); 328 retval = HAL_SPI_TransmitReceive_DMA(&hspi1, pOutput,(uint8_t*) &(global.dataSendToSlave), EXCHANGE_BUFFERSIZE);
311 if ( retval!= HAL_OK) { 329 if ( retval!= HAL_OK) {
312 SPI_Error_Handler(); 330 SPI_Error_Handler();