|
|
@@ -19,13 +19,12 @@ |
|
|
|
/* USER CODE END Header */ |
|
|
|
/* Includes ------------------------------------------------------------------*/ |
|
|
|
#include "main.h" |
|
|
|
#include "math.h" |
|
|
|
#include "stdbool.h" |
|
|
|
#include "string.h" |
|
|
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/ |
|
|
|
/* USER CODE BEGIN Includes */ |
|
|
|
|
|
|
|
#include "math.h" |
|
|
|
#include "stdbool.h" |
|
|
|
#include "string.h" |
|
|
|
/* USER CODE END Includes */ |
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/ |
|
|
@@ -46,9 +45,11 @@ |
|
|
|
/* Private variables ---------------------------------------------------------*/ |
|
|
|
RTC_HandleTypeDef hrtc; |
|
|
|
UART_HandleTypeDef huart2; |
|
|
|
|
|
|
|
/* USER CODE BEGIN PV */ |
|
|
|
RTC_TimeTypeDef sTime; |
|
|
|
RTC_DateTypeDef sDate; |
|
|
|
RTC_AlarmTypeDef sAlarm; |
|
|
|
RTC_AlarmTypeDef sAlarmA, sAlarmB; |
|
|
|
|
|
|
|
//Nuremberg coordinates |
|
|
|
int latitude_nbg = 49; |
|
|
@@ -72,9 +73,6 @@ typedef struct { |
|
|
|
int day; |
|
|
|
int year; |
|
|
|
} timeAndDate; |
|
|
|
|
|
|
|
/* USER CODE BEGIN PV */ |
|
|
|
|
|
|
|
/* USER CODE END PV */ |
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/ |
|
|
@@ -346,28 +344,28 @@ void calc_tomorrows_date(timeAndDate* initialDate, timeAndDate* tomorrowsDate) |
|
|
|
* Function Name : set_Alarm |
|
|
|
* Description : sets the wake up Alarm |
|
|
|
*******************************************************************************/ |
|
|
|
void set_Alarm(int h, int min, int weekDay, char* alarm) |
|
|
|
void set_Alarm(int h, int min, int weekDay, char* alarm, RTC_AlarmTypeDef* alarmInstance) |
|
|
|
{ |
|
|
|
/** Enable the Alarm A*/ |
|
|
|
|
|
|
|
sAlarm.AlarmTime.Hours = h; |
|
|
|
sAlarm.AlarmTime.Minutes = min; |
|
|
|
sAlarm.AlarmTime.Seconds = 0; |
|
|
|
sAlarm.AlarmTime.SubSeconds = 0; |
|
|
|
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; |
|
|
|
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; |
|
|
|
sAlarm.AlarmMask = RTC_ALARMMASK_NONE; //only by specific time |
|
|
|
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; |
|
|
|
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY; |
|
|
|
sAlarm.AlarmDateWeekDay = weekDay; |
|
|
|
alarmInstance->AlarmTime.Hours = h; |
|
|
|
alarmInstance->AlarmTime.Minutes = min; |
|
|
|
alarmInstance->AlarmTime.Seconds = 0; |
|
|
|
alarmInstance->AlarmTime.SubSeconds = 0; |
|
|
|
alarmInstance->AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; |
|
|
|
alarmInstance->AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; |
|
|
|
alarmInstance->AlarmMask = RTC_ALARMMASK_NONE; //only by specific time |
|
|
|
alarmInstance->AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; |
|
|
|
alarmInstance->AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY; |
|
|
|
alarmInstance->AlarmDateWeekDay = weekDay; |
|
|
|
|
|
|
|
if (strcmp("A", alarm) == 0) { |
|
|
|
sAlarm.Alarm = RTC_ALARM_A; |
|
|
|
alarmInstance->Alarm = RTC_ALARM_A; |
|
|
|
} else { |
|
|
|
sAlarm.Alarm = RTC_ALARM_B; |
|
|
|
alarmInstance->Alarm = RTC_ALARM_B; |
|
|
|
} |
|
|
|
|
|
|
|
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK) |
|
|
|
if (HAL_RTC_SetAlarm_IT(&hrtc, alarmInstance, RTC_FORMAT_BIN) != HAL_OK) |
|
|
|
{ |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
@@ -451,9 +449,11 @@ int main(void) |
|
|
|
|
|
|
|
/* Infinite loop */ |
|
|
|
/* USER CODE BEGIN WHILE */ |
|
|
|
|
|
|
|
while (1) |
|
|
|
{ |
|
|
|
/* USER CODE END WHILE */ |
|
|
|
|
|
|
|
/* USER CODE BEGIN 3 */ |
|
|
|
setTime(&initialDate); |
|
|
|
setDate(&initialDate); |
|
|
|
leap_year_check(initialDate.year); |
|
|
@@ -475,8 +475,8 @@ int main(void) |
|
|
|
// Go to Sleep |
|
|
|
|
|
|
|
|
|
|
|
set_Alarm(16, 18, 4, "A"); |
|
|
|
set_Alarm(16, 20, 4, "B"); |
|
|
|
set_Alarm(16, 18, 4, "A", &sAlarmA); |
|
|
|
set_Alarm(16, 20, 4, "B", &sAlarmB); |
|
|
|
|
|
|
|
HAL_Delay(5000); |
|
|
|
|
|
|
@@ -525,8 +525,7 @@ void SystemClock_Config(void) |
|
|
|
*/ |
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI; |
|
|
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
|
|
|
//RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
|
|
|
RCC_OscInitStruct.HSICalibrationValue = 16; |
|
|
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
|
|
|
RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
|
|
@@ -571,6 +570,10 @@ static void MX_RTC_Init(void) |
|
|
|
|
|
|
|
/* USER CODE END RTC_Init 0 */ |
|
|
|
|
|
|
|
RTC_TimeTypeDef sTime = {0}; |
|
|
|
RTC_DateTypeDef sDate = {0}; |
|
|
|
//RTC_AlarmTypeDef sAlarm = {0}; |
|
|
|
|
|
|
|
/* USER CODE BEGIN RTC_Init 1 */ |
|
|
|
|
|
|
|
/* USER CODE END RTC_Init 1 */ |
|
|
@@ -612,7 +615,33 @@ static void MX_RTC_Init(void) |
|
|
|
{ |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
|
|
|
|
/** Enable the Alarm A |
|
|
|
*/ |
|
|
|
/** |
|
|
|
sAlarm.AlarmTime.Hours = 0; |
|
|
|
sAlarm.AlarmTime.Minutes = 0; |
|
|
|
sAlarm.AlarmTime.Seconds = 0; |
|
|
|
sAlarm.AlarmTime.SubSeconds = 0; |
|
|
|
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; |
|
|
|
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; |
|
|
|
sAlarm.AlarmMask = RTC_ALARMMASK_NONE; |
|
|
|
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; |
|
|
|
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; |
|
|
|
sAlarm.AlarmDateWeekDay = 1; |
|
|
|
sAlarm.Alarm = RTC_ALARM_A; |
|
|
|
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK) |
|
|
|
{ |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
/** Enable the Alarm B |
|
|
|
*/ |
|
|
|
/* |
|
|
|
sAlarm.AlarmDateWeekDay = 1; |
|
|
|
sAlarm.Alarm = RTC_ALARM_B; |
|
|
|
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK) |
|
|
|
{ |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
/* USER CODE BEGIN RTC_Init 2 */ |
|
|
|
|
|
|
|
/* USER CODE END RTC_Init 2 */ |
|
|
@@ -686,7 +715,22 @@ static void MX_GPIO_Init(void) |
|
|
|
} |
|
|
|
|
|
|
|
/* USER CODE BEGIN 4 */ |
|
|
|
/** |
|
|
|
* @brief Alarm callback |
|
|
|
* @param hrtc: RTC handle |
|
|
|
* @retval None |
|
|
|
*/ |
|
|
|
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
|
|
|
{ |
|
|
|
/* Alarm generation */ |
|
|
|
transmit_uart("A: Alarm!!!!\r\n"); |
|
|
|
} |
|
|
|
|
|
|
|
void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) |
|
|
|
{ |
|
|
|
/* Alarm generation */ |
|
|
|
transmit_uart("B: Alarm!!!!\r\n"); |
|
|
|
} |
|
|
|
/* USER CODE END 4 */ |
|
|
|
|
|
|
|
/** |
|
|
@@ -704,24 +748,6 @@ void Error_Handler(void) |
|
|
|
/* USER CODE END Error_Handler_Debug */ |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief Alarm callback |
|
|
|
* @param hrtc: RTC handle |
|
|
|
* @retval None |
|
|
|
*/ |
|
|
|
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
|
|
|
{ |
|
|
|
/* Alarm generation */ |
|
|
|
transmit_uart("A: Alarm!!!!\r\n"); |
|
|
|
} |
|
|
|
|
|
|
|
void HAL_RTC_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) |
|
|
|
{ |
|
|
|
/* Alarm generation */ |
|
|
|
transmit_uart("B: Alarm!!!!\r\n"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_FULL_ASSERT |
|
|
|
/** |
|
|
|
* @brief Reports the name of the source file and the source line number |