Browse Source

Added working Alarm A and B

alice
Gregor Wüst 3 years ago
parent
commit
aee0133856
3 changed files with 89 additions and 59 deletions
  1. 8
    8
      RTC/.mxproject
  2. 72
    46
      RTC/Core/Src/main.c
  3. 9
    5
      RTC/RTC.ioc

+ 8
- 8
RTC/.mxproject View File

@@ -9,17 +9,17 @@ CDefines=USE_HAL_DRIVER;STM32F401xE;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=3
HeaderFiles#0=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Inc/stm32f4xx_it.h
HeaderFiles#1=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Inc/stm32f4xx_hal_conf.h
HeaderFiles#2=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Inc/main.h
HeaderFiles#0=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Inc/stm32f4xx_it.h
HeaderFiles#1=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Inc/stm32f4xx_hal_conf.h
HeaderFiles#2=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Inc/main.h
HeaderFolderListSize=1
HeaderPath#0=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Inc
HeaderPath#0=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Inc
HeaderFiles=;
SourceFileListSize=3
SourceFiles#0=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Src/stm32f4xx_it.c
SourceFiles#1=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Src/stm32f4xx_hal_msp.c
SourceFiles#2=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Src/main.c
SourceFiles#0=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Src/stm32f4xx_it.c
SourceFiles#1=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Src/stm32f4xx_hal_msp.c
SourceFiles#2=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Src/main.c
SourceFolderListSize=1
SourcePath#0=C:/Users/Gregor/Desktop/Projektarbeit/Workspace/RTC/Core/Src
SourcePath#0=C:/Users/wuest/Desktop/Studium/Master/Sem2/Projekt/Arbeit/uC/Motorsteuerung/RTC/Core/Src
SourceFiles=;


+ 72
- 46
RTC/Core/Src/main.c View File

@@ -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

+ 9
- 5
RTC/RTC.ioc View File

@@ -15,8 +15,9 @@ Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PB3
Mcu.Pin11=VP_RTC_VS_RTC_Activate
Mcu.Pin12=VP_RTC_VS_RTC_Calendar
Mcu.Pin13=VP_RTC_VS_RTC_Alarm_A_Intern
Mcu.Pin14=VP_SYS_VS_Systick
Mcu.Pin13=VP_RTC_VS_RTC_Alarm_B_Intern
Mcu.Pin14=VP_RTC_VS_RTC_Alarm_A_Intern
Mcu.Pin15=VP_SYS_VS_Systick
Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin3=PH0 - OSC_IN
Mcu.Pin4=PH1 - OSC_OUT
@@ -25,7 +26,7 @@ Mcu.Pin6=PA3
Mcu.Pin7=PA5
Mcu.Pin8=PA13
Mcu.Pin9=PA14
Mcu.PinsNb=15
Mcu.PinsNb=16
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F401RETx
@@ -157,9 +158,10 @@ RCC.VCOInputFreq_Value=1000000
RCC.VCOOutputFreq_Value=336000000
RCC.VcooutputI2S=96000000
RTC.Alarm=RTC_ALARM_A
RTC.Alarm_B=RTC_ALARM_B
RTC.Date=8
RTC.Format=RTC_FORMAT_BIN
RTC.IPParameters=Format,Date,Year,Alarm
RTC.IPParameters=Format,Date,Year,Alarm,Alarm_B
RTC.Year=21
SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1
@@ -169,10 +171,12 @@ VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate
VP_RTC_VS_RTC_Alarm_A_Intern.Mode=Alarm A
VP_RTC_VS_RTC_Alarm_A_Intern.Signal=RTC_VS_RTC_Alarm_A_Intern
VP_RTC_VS_RTC_Alarm_B_Intern.Mode=Alarm B
VP_RTC_VS_RTC_Alarm_B_Intern.Signal=RTC_VS_RTC_Alarm_B_Intern
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.Signal=SYS_VS_Systick
board=NUCLEO-F401RE
boardIOC=true
isbadioc=true
isbadioc=false

Loading…
Cancel
Save