# HG changeset patch # User heinrichsweikamp # Date 1574519798 -3600 # Node ID cb3870f79e9d449f8d5c76e432a7e8b6e5b56dc0 # Parent afa55a50cc724b11b959fa81567d59ede251ef22 Add Support for new end-2019 hardware: new pressure sensor MS5837 support with autodetect in pressure.c define the sensors in i2c.h minor typo fixed in scheduler.c advance version number and update release date in baseCPU2.c Beware: Messing up the I2C function may require factory maintance in gen 1 and gen 2 hardware! diff -r afa55a50cc72 -r cb3870f79e9d Small_CPU/Inc/i2c.h --- a/Small_CPU/Inc/i2c.h Wed Oct 09 20:05:47 2019 +0200 +++ b/Small_CPU/Inc/i2c.h Sat Nov 23 15:36:38 2019 +0100 @@ -3,7 +3,8 @@ #define I2C_H /* Pressure Sensor */ -#define DEVICE_PRESSURE 0xEE // 2019 hardware (gen 3) will use 0xEC (MS5837), all other use 0xEE (MS5803) +#define DEVICE_PRESSURE_MS5803 0xEE // gen 1 and gen 2 use 0xEE (MS5803) +#define DEVICE_PRESSURE_MS5837 0xEC // end-2019 hardware (gen 3) uses 0xEC (MS5837) /* Compass/Accelerometer */ #define DEVICE_ACCELARATOR_MMA8452Q 0x38 // Hardware gen 1 (Two chip solution with MMA8452Q and HMC5883L) diff -r afa55a50cc72 -r cb3870f79e9d Small_CPU/Src/baseCPU2.c --- a/Small_CPU/Src/baseCPU2.c Wed Oct 09 20:05:47 2019 +0200 +++ b/Small_CPU/Src/baseCPU2.c Sat Nov 23 15:36:38 2019 +0100 @@ -162,7 +162,7 @@ // See CPU2-RTE.ld const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { .versionFirst = 2, - .versionSecond = 0, + .versionSecond = 1, .versionThird = 0, .versionBeta = 0, @@ -170,13 +170,13 @@ .signature = "mh", .release_year = 19, - .release_month = 10, - .release_day = 6, + .release_month = 11, + .release_day = 23, .release_sub = 0, /* max 48 with trailing 0 */ //release_info ="12345678901234567890123456789012345678901" - .release_info = "stable Aug'19", + .release_info = "stable Nov'19", /* for safety reasons and coming functions */ .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, diff -r afa55a50cc72 -r cb3870f79e9d Small_CPU/Src/pressure.c --- a/Small_CPU/Src/pressure.c Wed Oct 09 20:05:47 2019 +0200 +++ b/Small_CPU/Src/pressure.c Sat Nov 23 15:36:38 2019 +0100 @@ -61,11 +61,13 @@ #define PRESSURE_SURFACE_DETECT_UNSTABLE_CNT (3u) /* Event count to detect unstable condition */ +static uint8_t PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; /* Default Address */ + static uint16_t get_ci_by_coef_num(uint8_t coef_num); //void pressure_calculation_new(void); //void pressure_calculation_old(void); static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void); -static uint8_t crc4(uint16_t n_prom[]); +//static uint8_t crc4(uint16_t n_prom[]); static HAL_StatusTypeDef pressure_sensor_get_data(void); static uint32_t get_adc(void); @@ -74,7 +76,7 @@ static uint16_t C[8] = { 1 }; static uint32_t D1 = 1; static uint32_t D2 = 1; -static uint8_t n_crc; +//static uint8_t n_crc; static int64_t C5_x_2p8 = 1; static int64_t C2_x_2p16 = 1; @@ -338,25 +340,49 @@ uint8_t init_pressure(void) { uint8_t buffer[1]; - buffer[0] = 0x1e; + buffer[0] = 0x1E; // Reset Command uint8_t retValue = 0xFF; pressureSensorInitSuccess = false; init_pressure_history(); +/* Probe new sensor first */ + retValue = I2C_Master_Transmit( DEVICE_PRESSURE_MS5837, buffer, 1); + if(retValue != HAL_OK) + { + PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; // use old sensor + HAL_Delay(100); + MX_I2C1_Init(); + if (global.I2C_SystemStatus != HAL_OK) + { + if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { + MX_I2C1_TestAndClear(); // do it a second time + } + MX_I2C1_Init(); + } + } + else + { + PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5837; // Success, use new sensor + } + HAL_Delay(3); //2.8ms according to datasheet + + buffer[0] = 0x1E; // Reset Command + retValue = 0xFF; + /* Send reset request to pressure sensor */ - retValue = I2C_Master_Transmit( DEVICE_PRESSURE, buffer, 1); + retValue = I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1); if(retValue != HAL_OK) { return (HAL_StatusTypeDef)retValue; } - HAL_Delay(3); + HAL_Delay(3); //2.8ms according to datasheet - for(uint8_t i=0;i<8;i++) + for(uint8_t i=0;i<7;i++) { C[i] = get_ci_by_coef_num(i); } - n_crc = crc4(C); // no evaluation at the moment hw 151026 + // n_crc = crc4(C); // no evaluation at the moment hw 151026 C5_x_2p8 = C[5] * 256; C2_x_2p16 = C[2] * 65536; @@ -379,8 +405,8 @@ uint32_t answer = 0; buffer[0] = 0x00; // Get ADC - I2C_Master_Transmit( DEVICE_PRESSURE, buffer, 1); - I2C_Master_Receive( DEVICE_PRESSURE, resivebuf, 4); + I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1); + I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 4); resivebuf[3] = 0; answer = 256*256 *(uint32_t)resivebuf[0] + 256 * (uint32_t)resivebuf[1] + (uint32_t)resivebuf[2]; @@ -393,8 +419,8 @@ uint8_t resivebuf[2]; uint8_t cmd = CMD_PROM_RD+coef_num*2; - I2C_Master_Transmit( DEVICE_PRESSURE, &cmd, 1); - I2C_Master_Receive( DEVICE_PRESSURE, resivebuf, 2); + I2C_Master_Transmit( PRESSURE_ADDRESS, &cmd, 1); + I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 2); return (256*(uint16_t)resivebuf[0]) + (uint16_t)resivebuf[1]; } @@ -437,7 +463,7 @@ uint8_t command = CMD_ADC_CONV + cmd; HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; - statusReturnTemp = I2C_Master_Transmit( DEVICE_PRESSURE, &command, 1); + statusReturnTemp = I2C_Master_Transmit( PRESSURE_ADDRESS, &command, 1); if(statusReturn) { @@ -705,7 +731,7 @@ /* taken from AN520 by meas-spec.com dated 9. Aug. 2011 * short and int are both 16bit according to AVR/GCC google results */ -static uint8_t crc4(uint16_t n_prom[]) +/*static uint8_t crc4(uint16_t n_prom[]) { uint16_t cnt; // simple counter uint16_t n_rem; // crc reminder @@ -734,7 +760,7 @@ n_prom[7]=crc_read; // restore the crc_read to its original place return (n_rem ^ 0x00); } -/* + void test_calculation(void) { C1 = 29112; diff -r afa55a50cc72 -r cb3870f79e9d Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Wed Oct 09 20:05:47 2019 +0200 +++ b/Small_CPU/Src/scheduler.c Sat Nov 23 15:36:38 2019 +0100 @@ -1030,7 +1030,7 @@ MX_I2C1_Init(); pressure_sensor_get_pressure_raw(); -/* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ +/* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occurred during startup */ if(global.I2C_SystemStatus != HAL_OK) { MX_I2C1_TestAndClear();