From 0d10df180682bb6f515287629305e6f5df454fde Mon Sep 17 00:00:00 2001 From: Gregor Wuest Date: Wed, 24 Feb 2021 13:47:03 +0100 Subject: [PATCH] added char concat function added fatfs --- RTC/Core/Src/main.c | 66 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/RTC/Core/Src/main.c b/RTC/Core/Src/main.c index 502dadd..5af768a 100644 --- a/RTC/Core/Src/main.c +++ b/RTC/Core/Src/main.c @@ -19,6 +19,7 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" +#include "fatfs.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -26,6 +27,8 @@ #include "stdbool.h" #include "string.h" #include +#include "fatfs_sd.h" +#include /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -44,6 +47,8 @@ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ +SPI_HandleTypeDef hspi1; +ADC_HandleTypeDef hadc; RTC_HandleTypeDef hrtc; UART_HandleTypeDef huart2; @@ -53,7 +58,6 @@ RTC_DateTypeDef sDate; RTC_AlarmTypeDef sAlarmA, sAlarmB; static volatile uint16_t gLastError; static volatile bool gButtonPressed = FALSE; -static volatile float sunWindow; //Nuremberg coordinates int latitude_nbg = 49; @@ -92,6 +96,20 @@ typedef struct { timeStamp time; +// SD CARD Variables +FATFS fs; +FATFS *pfs; +FIL fil; +FRESULT fres; +DWORD fre_clust; +uint32_t totalSpace, freeSpace; +char buffer[100]; +uint16_t AD_RES; +int num; + +//Variable name for txt file +char txtVar[19]; + /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -99,6 +117,8 @@ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); static void MX_RTC_Init(void); +static void MX_SPI1_Init(void); +static void MX_ADC_Init(void); static void MyFlagInterruptHandler(void); void ButtonHandler(void); /* USER CODE BEGIN PFP */ @@ -443,17 +463,6 @@ void set_time_and_date(timeAndDate *timeanddate){ } } -/*void setDate(timeAndDate *date){ - - if (HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN) == HAL_OK) - { - date->weekDay = sDate.WeekDay; - date->month = sDate.Month; - date->day = sDate.Date; - date->year = 2000 + sDate.Year; - } -}*/ - int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){ int duration_h=0; int duration_m=0; @@ -469,6 +478,20 @@ int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){ return (duration_h * 60 + duration_m) / leapsFor180Deg; } +char int_to_char_and_concat(int amount, char* separator, ...){ + va_list argumentlist; + va_start(argumentlist, separator); + char str[200] = ""; + + while (amount--){ + char arg = va_arg(argumentlist, char); + strcat(str, arg); + strcat(str, separator); + } + + return str; +} + /* USER CODE END 0 */ /** @@ -501,9 +524,13 @@ int main(void) MX_GPIO_Init(); MX_USART2_UART_Init(); MX_RTC_Init(); + MX_SPI1_Init(); + MX_FATFS_Init(); + MX_ADC_Init(); /* USER CODE BEGIN 2 */ - //----- Init of the Motor control library + //######### Inits of the Motor control library ######### + /* Set the L6208 library to use 1 device */ BSP_MotorControl_SetNbDevices(BSP_MOTOR_CONTROL_BOARD_ID_L6208, 1); BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, NULL); @@ -523,6 +550,17 @@ int main(void) /* Disable the power bridges after initialization */ BSP_MotorControl_CmdDisable(0); + //######### Mount SD-Card ######### + + fres = f_mount(&fs, "", 0); + if (fres == FR_OK) { + transmit_uart("SD card is mounted successfully!\r\n"); + } else if (fres != FR_OK) { + transmit_uart("SD card is not mounted!\r\n"); + } + + //######### Variable inits ######### + timeAndDate sunrise, sunset, wakeUpTimeForStep, tomorrowsDate, initialDate; sunrise = sunset = wakeUpTimeForStep = tomorrowsDate = initialDate = (timeAndDate) {\ 0, @@ -549,6 +587,8 @@ int main(void) while (1) { + //######### Motor settings and motor test ######### + HAL_Delay(2000); transmit_uart("Resetting motor position and calculating new dates and times.\r\n");