comparison Small_CPU/Src/pressure.c @ 488:9eeab3fead8f

Added "I2C_DeInit();" in hardware detection routines. It's the recommended way to do and solves potential issues with older OSTC4 hardware generations. Increased RTE and RTE required numbers updated "Current build"
author heinrichsweikamp
date Sat, 27 Jun 2020 18:40:32 +0200
parents 3fe9cc747c5c
children 666cafac87ab
comparison
equal deleted inserted replaced
487:0f5080f50ba7 488:9eeab3fead8f
335 retValue = I2C_Master_Transmit( DEVICE_PRESSURE_MS5837, buffer, 1); 335 retValue = I2C_Master_Transmit( DEVICE_PRESSURE_MS5837, buffer, 1);
336 if(retValue != HAL_OK) 336 if(retValue != HAL_OK)
337 { 337 {
338 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; // use old sensor 338 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; // use old sensor
339 HAL_Delay(100); 339 HAL_Delay(100);
340 I2C_DeInit();
341 HAL_Delay(100);
340 MX_I2C1_Init(); 342 MX_I2C1_Init();
341 if (global.I2C_SystemStatus != HAL_OK) 343 HAL_Delay(100);
342 {
343 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) {
344 MX_I2C1_TestAndClear(); // do it a second time
345 }
346 MX_I2C1_Init();
347 }
348 } 344 }
349 else 345 else
350 { 346 {
351 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5837; // Success, use new sensor 347 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5837; // Success, use new sensor
352 } 348 }
458 *statusReturn = statusReturnTemp; 454 *statusReturn = statusReturnTemp;
459 } 455 }
460 456
461 switch (cmd & 0x0f) // wait necessary conversion time 457 switch (cmd & 0x0f) // wait necessary conversion time
462 { 458 {
463 case CMD_ADC_256 : HAL_Delay(1); break; 459 case CMD_ADC_256 : HAL_Delay(2); break;
464 case CMD_ADC_512 : HAL_Delay(3); break; 460 case CMD_ADC_512 : HAL_Delay(4); break;
465 case CMD_ADC_1024: HAL_Delay(4); break; 461 case CMD_ADC_1024: HAL_Delay(5); break;
466 case CMD_ADC_2048: HAL_Delay(6); break; 462 case CMD_ADC_2048: HAL_Delay(7); break;
467 case CMD_ADC_4096: HAL_Delay(10); break; 463 case CMD_ADC_4096: HAL_Delay(11); break;
468 default: 464 default:
469 break; 465 break;
470 } 466 }
471 adcValue = get_adc(); 467 adcValue = get_adc();
472 if(adcValue == 0xFFFFFFFF) 468 /* if(adcValue == 0xFFFFFFFF)
473 { 469 {
474 if(statusReturn) 470 if(statusReturn)
475 { 471 {
476 *statusReturn = HAL_ERROR; 472 *statusReturn = HAL_ERROR;
477 } 473 }
478 } 474 }*/
475
479 return adcValue; 476 return adcValue;
480 } 477 }
481 478
482 479
483 static HAL_StatusTypeDef pressure_sensor_get_data(void) 480 static HAL_StatusTypeDef pressure_sensor_get_data(void)
486 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT; 483 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT;
487 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT; 484 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT;
488 485
489 486
490 487
491 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn2); 488 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_4096, &statusReturn2);
492 if (statusReturn2 == HAL_OK) 489 if (statusReturn2 == HAL_OK)
493 { 490 {
494 D2 = requestedValue; 491 D2 = requestedValue;
495 } 492 }
496 493
497 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn1); 494 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_4096, &statusReturn1);
498 if (statusReturn1 == HAL_OK) 495 if (statusReturn1 == HAL_OK)
499 { 496 {
500 D1 = requestedValue; 497 D1 = requestedValue;
501 } 498 }
502 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse 499 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse
509 HAL_StatusTypeDef pressure_sensor_get_pressure_raw(void) 506 HAL_StatusTypeDef pressure_sensor_get_pressure_raw(void)
510 { 507 {
511 uint32_t requestedValue = 0; 508 uint32_t requestedValue = 0;
512 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; 509 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
513 510
514 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn); 511 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_4096, &statusReturn);
515 if (statusReturn == HAL_OK) 512 if (statusReturn == HAL_OK)
516 { 513 {
517 D1 = requestedValue; 514 D1 = requestedValue;
518 } 515 }
519 516
524 HAL_StatusTypeDef pressure_sensor_get_temperature_raw(void) 521 HAL_StatusTypeDef pressure_sensor_get_temperature_raw(void)
525 { 522 {
526 uint32_t requestedValue = 0; 523 uint32_t requestedValue = 0;
527 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; 524 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
528 525
529 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn); 526 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_4096, &statusReturn);
530 if (statusReturn == HAL_OK) 527 if (statusReturn == HAL_OK)
531 { 528 {
532 D2 = requestedValue; 529 D2 = requestedValue;
533 } 530 }
534 return statusReturn; 531 return statusReturn;