Mercurial > public > ostc4
changeset 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 | b11e50415982 |
children | 2e2d34c1cc99 |
files | Small_CPU/Src/batteryGasGauge.c Small_CPU/Src/spi.c |
diffstat | 2 files changed, 41 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Src/batteryGasGauge.c Sun Jan 12 18:06:59 2020 +0100 +++ b/Small_CPU/Src/batteryGasGauge.c Sun Jan 12 19:50:14 2020 +0100 @@ -28,7 +28,7 @@ #include "stm32f4xx_hal.h" #include "i2c.h" -static float battery_f_voltage = 0; +static float battery_f_voltage = 6.0; /* max assumed voltage */ static float battery_f_charge_percent = 0; #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh) @@ -117,23 +117,25 @@ float battery_f_charge_percent_local; uint8_t bufferReceive[10]; - I2C_Master_Receive( DEVICE_BATTERYGAUGE, bufferReceive, 10); - - battery_f_voltage_local = (float)(bufferReceive[8] * 256); - battery_f_voltage_local += (float)(bufferReceive[9]); - battery_f_voltage_local *= (float)6 / (float)0xFFFF; + + if(I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10) == HAL_OK) + { + battery_f_voltage_local = (float)(bufferReceive[8] * 256); + battery_f_voltage_local += (float)(bufferReceive[9]); + battery_f_voltage_local *= (float)6 / (float)0xFFFF; + + // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh + battery_f_charge_percent_local = (float)(bufferReceive[2] * 256); + battery_f_charge_percent_local += (float)(bufferReceive[3]); + battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; + battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; - // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh - battery_f_charge_percent_local = (float)(bufferReceive[2] * 256); - battery_f_charge_percent_local += (float)(bufferReceive[3]); - battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; - battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; - - if(battery_f_charge_percent_local < 0) - battery_f_charge_percent_local = 0; - - battery_f_voltage = battery_f_voltage_local; - battery_f_charge_percent = battery_f_charge_percent_local; + if(battery_f_charge_percent_local < 0) + battery_f_charge_percent_local = 0; + + battery_f_voltage = battery_f_voltage_local; + battery_f_charge_percent = battery_f_charge_percent_local; + } }
--- a/Small_CPU/Src/spi.c Sun Jan 12 18:06:59 2020 +0100 +++ b/Small_CPU/Src/spi.c Sun Jan 12 19:50:14 2020 +0100 @@ -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);