|
@@ -72,6 +72,9 @@ static const uint16_t nixieCathodeMap[4][10] = {
|
|
|
static const uint8_t nixieCathodeMask[4][2] = {{0x00, 0x3f}, {0xc0, 0x0f}, {0xf0, 0x03}, {0xc0, 0x00}};
|
|
|
static uint8_t tubesBuffer[SPI_BUFFER_SIZE] = {0};
|
|
|
static rtc_t Clock;
|
|
|
+static struct bme280_dev SensorDev;
|
|
|
+static struct bme280_data SensorData;
|
|
|
+static int8_t rsltSensor = BME280_OK;
|
|
|
|
|
|
/* USER CODE END PV */
|
|
|
|
|
@@ -88,6 +91,8 @@ static void MX_TIM17_Init(void);
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
static void showDigit(tube_pos_t pos, uint8_t dig);
|
|
|
static void SPI_StartTX(void);
|
|
|
+static int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
|
|
|
+static int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
|
|
|
/* USER CODE END PFP */
|
|
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
@@ -177,12 +182,41 @@ int main(void)
|
|
|
|
|
|
RTC_Init();
|
|
|
while (Flag.I2C_TX_End == 0) { __NOP(); };
|
|
|
+
|
|
|
+ SensorDev.dev_id = BME280_I2C_ADDR_PRIM;
|
|
|
+ SensorDev.intf = BME280_I2C_INTF;
|
|
|
+ SensorDev.read = user_i2c_read;
|
|
|
+ SensorDev.write = user_i2c_write;
|
|
|
+ SensorDev.delay_ms = LL_mDelay;
|
|
|
+ rsltSensor = bme280_init(&SensorDev);
|
|
|
+ if (rsltSensor == BME280_OK) {
|
|
|
+ Flag.BME280 = 1;
|
|
|
+ }
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
RTC_ReadAll(&Clock);
|
|
|
while (Flag.I2C_RX_End == 0) { __NOP(); };
|
|
|
|
|
|
+ /* BME280 Recommended mode of operation: Indoor navigation */
|
|
|
+ SensorDev.settings.osr_h = BME280_OVERSAMPLING_1X;
|
|
|
+ SensorDev.settings.osr_p = BME280_OVERSAMPLING_16X;
|
|
|
+ SensorDev.settings.osr_t = BME280_OVERSAMPLING_2X;
|
|
|
+ SensorDev.settings.filter = BME280_FILTER_COEFF_16;
|
|
|
+
|
|
|
+ rsltSensor = bme280_set_sensor_settings((BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL), &SensorDev);
|
|
|
+ rsltSensor = bme280_set_sensor_mode(BME280_NORMAL_MODE, &SensorDev);
|
|
|
+ //SensorDev.delay_ms(50);
|
|
|
+ //rsltSensor = bme280_get_sensor_data(BME280_ALL, &SensorData, &SensorDev);
|
|
|
+ /* bme280_get_sensor_data(...) returns:
|
|
|
+ * - temperature in DegC, resolution is 0.01 DegC. Output value of "5123" equals 51.23 DegC.
|
|
|
+ * - pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits).
|
|
|
+ * Output value "24674867" represents 24674867/256 = 96386.2 Pa = 963.862 hPa.
|
|
|
+ * - humidity in %RH as unsigned 32 bit integer in Q22.10 format.
|
|
|
+ * Output value of "47445" represents 47445/1024 = 46.333 %RH
|
|
|
+ */
|
|
|
+ uint8_t temp_l, temp_h, hum_h, hum_l, pres_h, pres_l;
|
|
|
+ uint32_t tmp;
|
|
|
/* Infinite loop */
|
|
|
while (1)
|
|
|
{
|
|
@@ -190,7 +224,8 @@ int main(void)
|
|
|
COLOR_RGB(0, 0, 0);
|
|
|
LL_mDelay(500);
|
|
|
|
|
|
- RTC_ReadAll(&Clock);
|
|
|
+ //RTC_ReadAll(&Clock);
|
|
|
+ rsltSensor = bme280_get_sensor_data(BME280_ALL, &SensorData, &SensorDev);
|
|
|
|
|
|
if (Flag.RTC_IRQ != 0) {
|
|
|
Flag.RTC_IRQ = 0;
|
|
@@ -201,10 +236,36 @@ int main(void)
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
+/*
|
|
|
showDigit(Tube_A, Clock.Min >> 4);
|
|
|
showDigit(Tube_B, Clock.Min & 0xf);
|
|
|
showDigit(Tube_D, Clock.Sec >> 4);
|
|
|
showDigit(Tube_E, Clock.Sec & 0xf);
|
|
|
+*/
|
|
|
+ if (rsltSensor == BME280_OK) {
|
|
|
+ temp_h = (uint8_t)SensorData.temperature / 100;
|
|
|
+ temp_l = (uint8_t)SensorData.temperature % 100;
|
|
|
+
|
|
|
+ hum_h = (uint8_t)SensorData.humidity / 1024;
|
|
|
+ hum_l = (uint8_t)(((SensorData.humidity % 1024) + 5) / 10);
|
|
|
+
|
|
|
+ tmp = (SensorData.pressure + 128) / 256; // pressure in Pa
|
|
|
+ tmp *= 1000;
|
|
|
+ tmp += 66661;
|
|
|
+ tmp /= 133322; // pressure in mmHg
|
|
|
+ pres_h = (uint8_t)(tmp / 100);
|
|
|
+ pres_l = (uint8_t)(tmp % 100);
|
|
|
+
|
|
|
+ showDigit(Tube_A, temp_h >> 4);
|
|
|
+ showDigit(Tube_B, temp_h & 0xf);
|
|
|
+ showDigit(Tube_D, temp_l >> 4);
|
|
|
+ showDigit(Tube_E, temp_l & 0xf);
|
|
|
+ } else {
|
|
|
+ showDigit(Tube_A, 7);
|
|
|
+ showDigit(Tube_B, 7);
|
|
|
+ showDigit(Tube_D, 7);
|
|
|
+ showDigit(Tube_E, 7);
|
|
|
+ }
|
|
|
SPI_StartTX();
|
|
|
|
|
|
//__WFI();
|
|
@@ -217,6 +278,59 @@ static void SPI_StartTX(void) {
|
|
|
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
|
|
|
}
|
|
|
|
|
|
+static int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len) {
|
|
|
+ Flag.I2C_TX_End = 0;
|
|
|
+
|
|
|
+ DMA1_Channel2->CMAR = (uint32_t)data;
|
|
|
+ DMA1_Channel2->CPAR = (uint32_t)&(I2C1->RXDR);
|
|
|
+ DMA1_Channel2->CNDTR = len;
|
|
|
+ DMA1_Channel2->CCR |= DMA_CCR_EN;
|
|
|
+
|
|
|
+ while ( I2C1->ISR & I2C_ISR_BUSY ) {};
|
|
|
+
|
|
|
+ I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
|
|
|
+ I2C1->CR2 |= ( id | 1 << I2C_CR2_NBYTES_Pos );
|
|
|
+
|
|
|
+ I2C1->CR2 |= ( I2C_CR2_START );
|
|
|
+
|
|
|
+ while ( !( I2C1->CR2 & I2C_CR2_START ) ) {};
|
|
|
+ I2C1->TXDR = reg_addr;
|
|
|
+
|
|
|
+ while ( I2C1->ISR & I2C_ISR_BUSY ) {};
|
|
|
+ Flag.I2C_RX_End = 0;
|
|
|
+
|
|
|
+ I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
|
|
|
+ I2C1->CR2 |= ( id | len << I2C_CR2_NBYTES_Pos | I2C_CR2_RD_WRN);
|
|
|
+
|
|
|
+ I2C1->CR1 |= ( I2C_CR1_RXDMAEN );
|
|
|
+ I2C1->CR2 |= ( I2C_CR2_START );
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len) {
|
|
|
+ Flag.I2C_TX_End = 0;
|
|
|
+
|
|
|
+ //DMA1_Channel3->CCR &= ~DMA_CCR_EN;
|
|
|
+ DMA1_Channel3->CMAR = (uint32_t)data;
|
|
|
+ DMA1_Channel3->CPAR = (uint32_t)&(I2C1->TXDR);
|
|
|
+ DMA1_Channel3->CNDTR = len;
|
|
|
+
|
|
|
+ while ( I2C1->ISR & I2C_ISR_BUSY ) {};
|
|
|
+
|
|
|
+ I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
|
|
|
+ I2C1->CR2 |= ( id | (len + 1) << I2C_CR2_NBYTES_Pos );
|
|
|
+ I2C1->CR1 |= ( I2C_CR1_TXDMAEN );
|
|
|
+ I2C1->CR2 |= ( I2C_CR2_START );
|
|
|
+
|
|
|
+ while ( !( I2C1->CR2 & I2C_CR2_START ) ) {};
|
|
|
+ I2C1->TXDR = reg_addr;
|
|
|
+
|
|
|
+ DMA1_Channel3->CCR |= DMA_CCR_EN;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief System Clock Configuration
|
|
|
* @retval None
|