Browse Source

add RTC & calendar for timestamp

master
Daniel Peter Chokola 2 years ago
parent
commit
630d912c94
  1. 42
      .mxproject
  2. 2
      Core/Inc/stm32f4xx_hal_conf.h
  3. 32
      Core/Src/main.c
  4. 42
      hothouse-mon.ioc

42
.mxproject

File diff suppressed because one or more lines are too long

2
Core/Inc/stm32f4xx_hal_conf.h

@ -57,7 +57,7 @@
/* #define HAL_IWDG_MODULE_ENABLED */ /* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */ /* #define HAL_LTDC_MODULE_ENABLED */
/* #define HAL_RNG_MODULE_ENABLED */ /* #define HAL_RNG_MODULE_ENABLED */
/* #define HAL_RTC_MODULE_ENABLED */ #define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */ /* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */ /* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_MMC_MODULE_ENABLED */

32
Core/Src/main.c

@ -18,6 +18,7 @@
/* USER CODE END Header */ /* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "main.h" #include "main.h"
#include "rtc.h"
#include "spi.h" #include "spi.h"
#include "usb_device.h" #include "usb_device.h"
#include "gpio.h" #include "gpio.h"
@ -29,6 +30,7 @@
#include "sx127x.h" #include "sx127x.h"
#include "terminal.h" #include "terminal.h"
#include "stdio.h" #include "stdio.h"
#include "time.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
@ -71,7 +73,11 @@ int main(void)
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
bme280_t bme280; bme280_t bme280;
sx127x_t sx127x; sx127x_t sx127x;
uint8_t buf[200]; uint8_t buf[250];
RTC_TimeTypeDef time;
RTC_DateTypeDef date;
struct tm t = { 0 };
char timebuf[128];
uint16_t len; uint16_t len;
/* USER CODE END 1 */ /* USER CODE END 1 */
@ -96,6 +102,7 @@ int main(void)
MX_SPI2_Init(); MX_SPI2_Init();
MX_USB_DEVICE_Init(); MX_USB_DEVICE_Init();
MX_SPI1_Init(); MX_SPI1_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
HAL_GPIO_WritePin(BME280_PWR_GPIO_Port, BME280_PWR_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(BME280_PWR_GPIO_Port, BME280_PWR_Pin, GPIO_PIN_SET);
bme280_init(&bme280, &hspi2, SPI2_CS_GPIO_Port, SPI2_CS_Pin); bme280_init(&bme280, &hspi2, SPI2_CS_GPIO_Port, SPI2_CS_Pin);
@ -107,14 +114,24 @@ int main(void)
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
while(1) while(1)
{ {
term_printf("T: %f DegC, P: %f hPa, H: %f %%RH\r\n", HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
(double) bme280_temp_get(&bme280) / 100.0, HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
(double) bme280_press_get(&bme280) / 25600.0, t.tm_sec = time.Seconds; /* Seconds [0, 60] */
(double) bme280_hum_get(&bme280) / 1024.0); t.tm_min = time.Minutes; /* Minutes [0, 59] */
len = snprintf((char *) buf, 200, "T: %f DegC, P: %f hPa, H: %f %%RH\r\n", t.tm_hour = time.Hours; /* Hour [0, 23] */
t.tm_mday = date.Date; /* Day of the month [1, 31] */
t.tm_mon = date.Month; /* Month [0, 11] (January = 0) */
t.tm_year = date.Year + 100; /* Year minus 1900 */
t.tm_wday = date.WeekDay; /* Day of the week [0, 6] (Sunday = 0) */
t.tm_yday = 0; /* Day of the year [0, 365] (Jan/01 = 0) */
t.tm_isdst = 0; /* Daylight savings flag */
strftime(timebuf, 256, "%Y-%m-%d %H:%M:%S", &t);
len = snprintf((char *) buf, 200, "%s T: %.2f\xc2\xb0""C, P: %.2f hPa, RH: %.2f%%\r\n",
timebuf,
(double) bme280_temp_get(&bme280) / 100.0, (double) bme280_temp_get(&bme280) / 100.0,
(double) bme280_press_get(&bme280) / 25600.0, (double) bme280_press_get(&bme280) / 25600.0,
(double) bme280_hum_get(&bme280) / 1024.0); (double) bme280_hum_get(&bme280) / 1024.0);
term_printf("%s", buf);
sx127x_tx(&sx127x, buf, len); sx127x_tx(&sx127x, buf, len);
HAL_Delay(1000); HAL_Delay(1000);
} }
@ -141,8 +158,9 @@ void SystemClock_Config(void)
/** Initializes the RCC Oscillators according to the specified parameters /** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure. * in the RCC_OscInitTypeDef structure.
*/ */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLM = 25;

42
hothouse-mon.ioc

@ -8,12 +8,13 @@ Mcu.CPN=STM32F401CCU6
Mcu.Family=STM32F4 Mcu.Family=STM32F4
Mcu.IP0=NVIC Mcu.IP0=NVIC
Mcu.IP1=RCC Mcu.IP1=RCC
Mcu.IP2=SPI1 Mcu.IP2=RTC
Mcu.IP3=SPI2 Mcu.IP3=SPI1
Mcu.IP4=SYS Mcu.IP4=SPI2
Mcu.IP5=USB_DEVICE Mcu.IP5=SYS
Mcu.IP6=USB_OTG_FS Mcu.IP6=USB_DEVICE
Mcu.IPNb=7 Mcu.IP7=USB_OTG_FS
Mcu.IPNb=8
Mcu.Name=STM32F401C(B-C)Ux Mcu.Name=STM32F401C(B-C)Ux
Mcu.Package=UFQFPN48 Mcu.Package=UFQFPN48
Mcu.Pin0=PC13-ANTI_TAMP Mcu.Pin0=PC13-ANTI_TAMP
@ -25,9 +26,11 @@ Mcu.Pin13=PA15
Mcu.Pin14=PB3 Mcu.Pin14=PB3
Mcu.Pin15=PB4 Mcu.Pin15=PB4
Mcu.Pin16=PB5 Mcu.Pin16=PB5
Mcu.Pin17=VP_SYS_VS_Systick Mcu.Pin17=VP_RTC_VS_RTC_Activate
Mcu.Pin18=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS Mcu.Pin18=VP_RTC_VS_RTC_Calendar
Mcu.Pin19=VP_SYS_VS_Systick
Mcu.Pin2=PC15-OSC32_OUT Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin20=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
Mcu.Pin3=PH0 - OSC_IN Mcu.Pin3=PH0 - OSC_IN
Mcu.Pin4=PH1 - OSC_OUT Mcu.Pin4=PH1 - OSC_OUT
Mcu.Pin5=PB12 Mcu.Pin5=PB12
@ -35,7 +38,7 @@ Mcu.Pin6=PB13
Mcu.Pin7=PB14 Mcu.Pin7=PB14
Mcu.Pin8=PB15 Mcu.Pin8=PB15
Mcu.Pin9=PA11 Mcu.Pin9=PA11
Mcu.PinsNb=19 Mcu.PinsNb=21
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F401CCUx Mcu.UserName=STM32F401CCUx
@ -128,7 +131,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation= ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_SPI2_Init-SPI2-false-HAL-true,4-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,5-MX_SPI1_Init-SPI1-false-HAL-true ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_SPI2_Init-SPI2-false-HAL-true,4-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_RTC_Init-RTC-false-HAL-true
RCC.48MHZClocksFreq_Value=48000000 RCC.48MHZClocksFreq_Value=48000000
RCC.AHBFreq_Value=72000000 RCC.AHBFreq_Value=72000000
RCC.APB1CLKDivider=RCC_HCLK_DIV2 RCC.APB1CLKDivider=RCC_HCLK_DIV2
@ -142,14 +145,16 @@ RCC.HCLKFreq_Value=72000000
RCC.HSE_VALUE=25000000 RCC.HSE_VALUE=25000000
RCC.HSI_VALUE=16000000 RCC.HSI_VALUE=16000000
RCC.I2SClocksFreq_Value=96000000 RCC.I2SClocksFreq_Value=96000000
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,RCC_RTC_Clock_Source,RCC_RTC_Clock_SourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S
RCC.LSI_VALUE=32000 RCC.LSI_VALUE=32000
RCC.PLLCLKFreq_Value=72000000 RCC.PLLCLKFreq_Value=72000000
RCC.PLLM=25 RCC.PLLM=25
RCC.PLLN=144 RCC.PLLN=144
RCC.PLLQ=3 RCC.PLLQ=3
RCC.PLLQCLKFreq_Value=48000000 RCC.PLLQCLKFreq_Value=48000000
RCC.RTCFreq_Value=32000 RCC.RCC_RTC_Clock_Source=RCC_RTCCLKSOURCE_LSE
RCC.RCC_RTC_Clock_SourceVirtual=RCC_RTCCLKSOURCE_LSE
RCC.RTCFreq_Value=32768
RCC.RTCHSEDivFreq_Value=12500000 RCC.RTCHSEDivFreq_Value=12500000
RCC.SYSCLKFreq_VALUE=72000000 RCC.SYSCLKFreq_VALUE=72000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
@ -157,6 +162,15 @@ RCC.VCOI2SOutputFreq_Value=192000000
RCC.VCOInputFreq_Value=1000000 RCC.VCOInputFreq_Value=1000000
RCC.VCOOutputFreq_Value=144000000 RCC.VCOOutputFreq_Value=144000000
RCC.VcooutputI2S=96000000 RCC.VcooutputI2S=96000000
RTC.Date=1
RTC.DayLightSaving=RTC_DAYLIGHTSAVING_ADD1H
RTC.Format=RTC_FORMAT_BIN
RTC.Hours=0
RTC.IPParameters=Format,DayLightSaving,Month,Date,WeekDay,Hours,Minutes,Year
RTC.Minutes=0
RTC.Month=RTC_MONTH_JANUARY
RTC.WeekDay=RTC_WEEKDAY_MONDAY
RTC.Year=0
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8 SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8
SPI1.CalculateBaudRate=9.0 MBits/s SPI1.CalculateBaudRate=9.0 MBits/s
SPI1.Direction=SPI_DIRECTION_2LINES SPI1.Direction=SPI_DIRECTION_2LINES
@ -175,6 +189,10 @@ USB_DEVICE.VirtualMode=Cdc
USB_DEVICE.VirtualModeFS=Cdc_FS USB_DEVICE.VirtualModeFS=Cdc_FS
USB_OTG_FS.IPParameters=VirtualMode USB_OTG_FS.IPParameters=VirtualMode
USB_OTG_FS.VirtualMode=Device_Only USB_OTG_FS.VirtualMode=Device_Only
VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate
VP_RTC_VS_RTC_Calendar.Mode=RTC_Calendar
VP_RTC_VS_RTC_Calendar.Signal=RTC_VS_RTC_Calendar
VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS

Loading…
Cancel
Save