Browse Source

Remove SHT sensor support.

Vladimir N. Shilov 3 years ago
parent
commit
3033d1a1ce
2 changed files with 3 additions and 194 deletions
  1. 2 8
      Inc/main.h
  2. 1 186
      Src/main.c

+ 2 - 8
Inc/main.h

@@ -90,7 +90,7 @@ typedef union {
     uint8_t u8L;          // element specifier for accessing high u8
     #endif
   } s16;                  // element spec. for acc. struct with low or high u8
-} nt16;
+} nt16_t;
 
 typedef union {
   uint32_t u32;           // element specifier for accessing whole u32
@@ -104,7 +104,7 @@ typedef union {
     uint16_t u16L;        // element specifier for accessing high u16
     #endif
   } s32;                  // element spec. for acc. struct with low or high u16
-} nt32;
+} nt32_t;
 
 /* USER CODE END ET */
 
@@ -114,12 +114,6 @@ typedef union {
 #define I2C_RET_NACK  (int8_t)-1
 #define I2C_RET_ERR   (int8_t)-2
 
-#define SHT_I2C_ADDR  0x80
-#define SHT_SOFT_RST  0xFE
-#define SHT_STRT_HUMD 0xF5
-#define SHT_STRT_TEMP 0xF3
-#define SHT_DATA_LEN  3
-
 /* USER CODE END EC */
 
 /* Exported macro ------------------------------------------------------------*/

+ 1 - 186
Src/main.c

@@ -75,7 +75,7 @@ static rtc_t Clock;
 static struct bme280_dev SensorDev;
 static struct bme280_data SensorData;
 static int8_t rsltSensor = -1; //BME280_OK;
-static int16_t Humidity, Temperature;
+static int16_t Humidity, Temperature, Pressure;
 /* USER CODE END PV */
 
 /* Private function prototypes -----------------------------------------------*/
@@ -93,12 +93,6 @@ static void showDigit(tube_pos_t pos, uint8_t dig);
 static void SPI_StartTX(void);
 int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
 int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
-int8_t user_i2c_write_byte(uint8_t id, uint8_t data);
-static int8_t SHT_Init(void);
-static int8_t SHT_StartH(void);
-static int8_t SHT_StartT(void);
-static int16_t SHT_GetH(void);
-static int16_t SHT_GetT(void);
 /* USER CODE END PFP */
 
 /* Private user code ---------------------------------------------------------*/
@@ -197,8 +191,6 @@ int main(void)
 COLOR_RGB(255, 0, 0);
     Flag.BME280 = 1;
   }
-
-  //SHT_Init();
   /* USER CODE END 2 */
 
   /* USER CODE BEGIN WHILE */
@@ -234,8 +226,6 @@ COLOR_RGB(255, 0, 0);
     if (Flag.BME280 != 0) {
       rsltSensor = bme280_set_sensor_mode(BME280_FORCED_MODE, &SensorDev);
     }
-//    SHT_StartH();
-//    SHT_StartT();
     tdelay_ms(500);
 
     if (Flag.RTC_IRQ != 0) {
@@ -256,26 +246,6 @@ COLOR_RGB(255, 0, 0);
     showDigit(Tube_D, Clock.Sec >> 4);
     showDigit(Tube_E, Clock.Sec & 0xf);
 */
-/*
-    Humidity = SHT_GetH();
-    hum_h = Humidity / 100;
-    hum_l = Humidity % 100;
-
-    showDigit(Tube_A, hum_h / 10);
-    showDigit(Tube_B, hum_h % 10);
-    showDigit(Tube_D, hum_l / 10);
-    showDigit(Tube_E, hum_l % 10);
-*/
-/*
-    Temperature = SHT_GetT();
-    temp_h = Temperature / 100;
-    temp_l = Temperature % 100;
-
-    showDigit(Tube_A, temp_h / 10);
-    showDigit(Tube_B, temp_h % 10);
-    showDigit(Tube_D, temp_l / 10);
-    showDigit(Tube_E, temp_l % 10);
-*/
 
     if (rsltSensor == BME280_OK) {
       tmp = SensorData.temperature + 50;
@@ -440,161 +410,6 @@ int8_t user_i2c_write(const uint8_t id, const uint8_t reg_addr, uint8_t *data, c
   return I2C_RET_OK;
 }
 
-/**
- * @brief Write one byte to I2C bus.
- * @retval I2C return code
- */
-int8_t user_i2c_write_byte(const uint8_t id, const uint8_t data) {
-  /* wait for i2c */
-  while ( I2C1->ISR & I2C_ISR_BUSY ) {};
-
-  /* prepare i2c for sending data byte */
-  I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
-  I2C1->CR2 |= ( id | 1 << I2C_CR2_NBYTES_Pos );
-  I2C1->CR1 |= I2C_CR1_NOSTRETCH;
-
-  /* gen START */
-  I2C1->CR2 |= ( I2C_CR2_START );
-
-  /* wait for start end */
-  while ( !( I2C1->CR2 & I2C_CR2_START ) ) {};
-
-  /* check if device is present */
-  if ((I2C1->ISR & I2C_ISR_NACKF) != 0) {
-    /* no device present, reset i2c */
-    I2C1->CR1 &= ~I2C_CR1_PE;
-    while ((I2C1->CR1 & I2C_CR1_PE) != 0) {};
-    I2C1->CR1 |= I2C_CR1_PE;
-    /* exit with NACK */
-    return I2C_RET_NACK;
-  }
-
-  /* device ok, data */
-  I2C1->TXDR = data;
-
-  return I2C_RET_OK;
-}
-
-/**
- * @brief Init DHT21/SHT21/Si7021 sensor, need wait for 15 ms
- * @retval I2C return code
- */
-static int8_t SHT_Init(void) {
-  int8_t res;
-
-  res = user_i2c_write_byte (SHT_I2C_ADDR, SHT_SOFT_RST);
-  if (res == I2C_RET_OK) {
-      tdelay_ms(15);
-  }
-
-  return res;
-}
-
-/**
- * @brief Launch Humidity measure for DHT21/SHT21/Si7021 sensor, need wait for 16 ms
- * @retval I2C return code
- */
-static int8_t SHT_StartH(void) {
-  int8_t res;
-
-  res = user_i2c_write_byte (SHT_I2C_ADDR, SHT_STRT_HUMD);
-  if (res == I2C_RET_OK) {
-      tdelay_ms(16);
-  }
-
-  return res;
-}
-
-/**
- * @brief Launch Temperature measure for DHT21/SHT21/Si7021 sensor, need wait for 50 ms
- */
-static int8_t SHT_StartT(void) {
-  int8_t res;
-
-  res = user_i2c_write_byte (SHT_I2C_ADDR, SHT_STRT_TEMP);
-  if (res == I2C_RET_OK) {
-      tdelay_ms(50);
-  }
-
-  return res;
-}
-
-/**
- * @brief Read and convert Humidity data from DHT21/SHT21/Si7021 sensor.
- * @retval Return value in 0.01 % [0..10000]
- */
-static int16_t SHT_GetH(void) {
-  uint8_t buf[4];
-  uint32_t rh;
-
-  /* wait for i2c */
-  while ( I2C1->ISR & I2C_ISR_BUSY ) {
-  }
-
-  /* prepare dma channel for receiving data */
-  DMA1_Channel2->CMAR = (uint32_t)buf;
-  DMA1_Channel2->CPAR = (uint32_t)&(I2C1->RXDR);
-  DMA1_Channel2->CNDTR = SHT_DATA_LEN;
-  DMA1_Channel2->CCR |= DMA_CCR_EN;
-
-  /* prepare i2c for receiving data */
-  I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
-  I2C1->CR2 |= ( SHT_I2C_ADDR | SHT_DATA_LEN << I2C_CR2_NBYTES_Pos | I2C_CR2_RD_WRN);
-  /* launch receiving */
-  I2C1->CR1 |= ( I2C_CR1_RXDMAEN );
-  I2C1->CR2 |= ( I2C_CR2_START );
-
-  while (Flag.I2C_RX_End == 0) {
-    __WFI();
-  }
-
-  rh = (buf[0] << 8) | buf[1];
-  rh *= 12500;
-  rh += 32768;
-  rh >>= 16;
-  rh -= 600;
-
-  return (int16_t)rh;
-}
-
-/**
- * @brief Read and convert Temperature data from DHT21/SHT21/Si7021 sensor.
- * @retval Return value in 0.01 oC [-4000..+8500]
- */
-static int16_t SHT_GetT(void) {
-  uint8_t buf[4];
-  uint32_t temp;
-
-  /* wait for i2c */
-  while ( I2C1->ISR & I2C_ISR_BUSY ) {
-  }
-
-  /* prepare dma channel for receiving data */
-  DMA1_Channel2->CMAR = (uint32_t)buf;
-  DMA1_Channel2->CPAR = (uint32_t)&(I2C1->RXDR);
-  DMA1_Channel2->CNDTR = SHT_DATA_LEN;
-  DMA1_Channel2->CCR |= DMA_CCR_EN;
-
-  /* prepare i2c for receiving data */
-  I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
-  I2C1->CR2 |= ( SHT_I2C_ADDR | SHT_DATA_LEN << I2C_CR2_NBYTES_Pos | I2C_CR2_RD_WRN);
-  /* launch receiving */
-  I2C1->CR1 |= ( I2C_CR1_RXDMAEN );
-  I2C1->CR2 |= ( I2C_CR2_START );
-
-  while (Flag.I2C_RX_End == 0) {
-    __WFI();
-  }
-
-  temp = (buf[0] << 8) | buf[1];
-  temp *= 17572;
-  temp += 32768;
-  temp >>= 16;
-  temp -= 4685;
-
-  return (int16_t)temp;
-}
-
 /**
   * @brief System Clock Configuration
   * @retval None