EXPERIMENT: simple lcd test

This commit is contained in:
Robin Dietzel 2022-12-09 15:47:21 +01:00
parent a0110696ae
commit 0c0f7a5be0

View File

@ -1,446 +1,463 @@
/* USER CODE BEGIN Header */ /* USER CODE BEGIN Header */
/** /**
****************************************************************************** ******************************************************************************
* @file : main.c * @file : main.c
* @brief : Main program body * @brief : Main program body
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* Copyright (c) 2022 STMicroelectronics. * Copyright (c) 2022 STMicroelectronics.
* All rights reserved. * All rights reserved.
* *
* This software is licensed under terms that can be found in the LICENSE file * This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component. * in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS. * If no LICENSE file comes with this software, it is provided AS-IS.
* *
****************************************************************************** ******************************************************************************
*/ */
/* USER CODE END Header */ /* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "main.h" #include "main.h"
#include "usb_device.h" #include "usb_device.h"
#include "LCD_I2C_Driver.h"
#define SLAVE_ADDRESS_LCD 0x4e
#define SLAVE_ADDRESS_LCD 0x4e
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */ /* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */ /* Private define ------------------------------------------------------------*/
/* USER CODE END PD */ /* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */ /* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1; /* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
I2C_HandleTypeDef hi2c1;
I2C_HandleTypeDef hi2c1;
RTC_HandleTypeDef hrtc;
RTC_HandleTypeDef hrtc;
/* USER CODE BEGIN PV */
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void); /* Private function prototypes -----------------------------------------------*/
static void MX_GPIO_Init(void); void SystemClock_Config(void);
static void MX_RTC_Init(void); static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void); static void MX_RTC_Init(void);
static void MX_I2C1_Init(void); static void MX_ADC1_Init(void);
/* USER CODE BEGIN PFP */ static void MX_I2C1_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */ /* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void lcd_send_cmd (char cmd)
{ void lcd_send_cmd (char cmd)
char data_u, data_l; {
uint8_t data_t[4]; char data_u, data_l;
data_u = (cmd & 0xf0); uint8_t data_t[4];
data_l = ((cmd << 4) & 0xf0); data_u = (cmd & 0xf0);
data_t[0] = data_u|0x0C; //en=1, rs=0 data_l = ((cmd << 4) & 0xf0);
data_t[1] = data_u|0x08; //en=0, rs=0 data_t[0] = data_u|0x0C; //en=1, rs=0
data_t[2] = data_l|0x0C; //en=1, rs=0 data_t[1] = data_u|0x08; //en=0, rs=0
data_t[3] = data_l|0x08; //en=0, rs=0 data_t[2] = data_l|0x0C; //en=1, rs=0
HAL_I2C_Master_Transmit (&hi2c1, SLAVE_ADDRESS_LCD, (uint8_t *) data_t, 4, 100); data_t[3] = data_l|0x08; //en=0, rs=0
} HAL_I2C_Master_Transmit (&hi2c1, SLAVE_ADDRESS_LCD, (uint8_t *) data_t, 4, 100);
}
void lcd_send_data (char data)
{ void lcd_send_data (char data)
char data_u, data_l; {
uint8_t data_t[4]; char data_u, data_l;
data_u = (data&0xf0); uint8_t data_t[4];
data_l = ((data<<4)&0xf0); data_u = (data&0xf0);
data_t[0] = data_u|0x0D; //en=1, rs=1 data_l = ((data<<4)&0xf0);
data_t[1] = data_u|0x09; //en=0, rs=1 data_t[0] = data_u|0x0D; //en=1, rs=1
data_t[2] = data_l|0x0D; //en=1, rs=1 data_t[1] = data_u|0x09; //en=0, rs=1
data_t[3] = data_l|0x09; //en=0, rs=1 data_t[2] = data_l|0x0D; //en=1, rs=1
HAL_I2C_Master_Transmit (&hi2c1, SLAVE_ADDRESS_LCD,(uint8_t *) data_t, 4, 100); data_t[3] = data_l|0x09; //en=0, rs=1
} HAL_I2C_Master_Transmit (&hi2c1, SLAVE_ADDRESS_LCD,(uint8_t *) data_t, 4, 100);
}
void lcd_init (void)
{ void lcd_init (void)
// 4 bit initialisation {
HAL_Delay(50); // wait for >40ms // Initialization by Instruction (from HD44780U Datasheet)
lcd_send_cmd (0x30); HAL_Delay(50); // wait for >40ms
HAL_Delay(5); // wait for >4.1ms lcd_send_cmd (0x30);
lcd_send_cmd (0x30); HAL_Delay(5); // wait for >4.1ms
HAL_Delay(1); // wait for >100us lcd_send_cmd (0x30);
lcd_send_cmd (0x30); HAL_Delay(1); // wait for >100us
HAL_Delay(10); lcd_send_cmd (0x30);
lcd_send_cmd (0x20); // 4bit mode HAL_Delay(10); // Wait for command execution lengt
HAL_Delay(10);
lcd_send_cmd (0x20); // Set Interface to 4-bit mode
// dislay initialisation HAL_Delay(10);
lcd_send_cmd (0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2 line display) F = 0 (5x8 characters)
HAL_Delay(1); lcd_send_cmd (0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2 line display) F = 0 (5x8 characters)
lcd_send_cmd (0x08); //Display on/off control --> D=0,C=0, B=0 ---> display off HAL_Delay(1);
HAL_Delay(1);
lcd_send_cmd (0x01); // clear display lcd_send_cmd (0x08); //Display on/off control --> D=0,C=0, B=0 ---> display off
HAL_Delay(1); HAL_Delay(1);
HAL_Delay(1); lcd_send_cmd (0x01); // clear display
lcd_send_cmd (0x06); //Entry mode set --> I/D = 1 (increment cursor) & S = 0 (no shift) HAL_Delay(1);
HAL_Delay(1); HAL_Delay(1);
lcd_send_cmd (0x0C); //Display on/off control --> D = 1, C and B = 0. (Cursor and blink, last two bits) lcd_send_cmd (0x06); //Entry mode set --> I/D = 1 (increment cursor) & S = 0 (no shift)
} HAL_Delay(1);
lcd_send_cmd (0x0C); //Display on/off control --> D = 1, C and B = 0. (Cursor and blink, last two bits)
void lcd_send_string (char *str) { }
while (*str) lcd_send_data(*str++);
} void lcd_send_string (char *str) {
while (*str) lcd_send_data(*str++);
/* USER CODE END 0 */ }
/** /* USER CODE END 0 */
* @brief The application entry point.
* @retval int /**
*/ * @brief The application entry point.
int main(void) * @retval int
{ */
/* USER CODE BEGIN 1 */ int main(void)
uint16_t value; {
/* USER CODE END 1 */ /* USER CODE BEGIN 1 */
uint16_t value;
/* MCU Configuration--------------------------------------------------------*/ /* USER CODE END 1 */
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ /* MCU Configuration--------------------------------------------------------*/
HAL_Init();
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
/* USER CODE BEGIN Init */ HAL_Init();
/* USER CODE END Init */ /* USER CODE BEGIN Init */
/* Configure the system clock */ /* USER CODE END Init */
SystemClock_Config();
/* Configure the system clock */
/* USER CODE BEGIN SysInit */ SystemClock_Config();
/* USER CODE END SysInit */ /* USER CODE BEGIN SysInit */
/* Initialize all configured peripherals */ /* USER CODE END SysInit */
MX_GPIO_Init();
MX_RTC_Init(); /* Initialize all configured peripherals */
MX_USB_DEVICE_Init(); MX_GPIO_Init();
MX_ADC1_Init(); MX_RTC_Init();
MX_I2C1_Init(); MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */ MX_ADC1_Init();
char buf [] = "SensorTest"; MX_I2C1_Init();
//CDC_Transmit_FS(buf, sizeof(buf)); /* USER CODE BEGIN 2 */
char buf [] = "Hallo THM";
lcd_init(); //CDC_Transmit_FS(buf, sizeof(buf));
/* USER CODE END 2 */
floatpump::LCD_I2C_Driver display(hi2c1, SLAVE_ADDRESS_LCD);
/* Infinite loop */ display.LCDInitialize();
/* USER CODE BEGIN WHILE */ display.LCDSetBacklight(true);
while (1) display.LCDSendCString(buf);
{ HAL_Delay(1000);
/* USER CODE END WHILE */ display.LCDPower(false);
HAL_Delay(1000);
/* USER CODE BEGIN 3 */ display.LCDPower(true);
HAL_Delay(1000);
HAL_ADC_Start(&hadc1); display.LCDCursor(true);
HAL_ADC_PollForConversion(&hadc1, 1); display.LCDCursorBlink(true);
value = HAL_ADC_GetValue(&hadc1);
HAL_Delay(1000);
char buf [250] = ""; display.LCDSetCursor(18, 3);
sprintf(buf, "Value: %d \r\n", value); display.LCDSendCString("XX");
//CDC_Transmit_FS(buf, sizeof(buf));
lcd_send_cmd (0x80|0x00); /* USER CODE END 2 */
lcd_send_string(buf);
HAL_Delay(1000); /* Infinite loop */
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); /* USER CODE BEGIN WHILE */
while (1)
{
} /* USER CODE END WHILE */
/* USER CODE END 3 */
} /* USER CODE BEGIN 3 */
/**
* @brief System Clock Configuration HAL_ADC_Start(&hadc1);
* @retval None HAL_ADC_PollForConversion(&hadc1, 1);
*/ value = HAL_ADC_GetValue(&hadc1);
void SystemClock_Config(void)
{ char buf [250] = "";
RCC_OscInitTypeDef RCC_OscInitStruct = {0}; sprintf(buf, "Value: %d \r\n", value);
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; //CDC_Transmit_FS(buf, sizeof(buf));
//display.LCDSendCString(buf);
/** Configure the main internal regulator output voltage HAL_Delay(1000);
*/ HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
}
/** Initializes the RCC Oscillators according to the specified parameters /* USER CODE END 3 */
* in the RCC_OscInitTypeDef structure. }
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; /**
RCC_OscInitStruct.HSEState = RCC_HSE_ON; * @brief System Clock Configuration
RCC_OscInitStruct.LSIState = RCC_LSI_ON; * @retval None
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; */
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; void SystemClock_Config(void)
RCC_OscInitStruct.PLL.PLLM = 25; {
RCC_OscInitStruct.PLL.PLLN = 192; RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.PLL.PLLQ = 4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) /** Configure the main internal regulator output voltage
{ */
Error_Handler(); __HAL_RCC_PWR_CLK_ENABLE();
} __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB buses clocks /** Initializes the RCC Oscillators according to the specified parameters
*/ * in the RCC_OscInitTypeDef structure.
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK */
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) RCC_OscInitStruct.PLL.PLLN = 192;
{ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
Error_Handler(); RCC_OscInitStruct.PLL.PLLQ = 4;
} if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
} {
Error_Handler();
/** }
* @brief ADC1 Initialization Function
* @param None /** Initializes the CPU, AHB and APB buses clocks
* @retval None */
*/ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
static void MX_ADC1_Init(void) |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
{ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
/* USER CODE BEGIN ADC1_Init 0 */ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
/* USER CODE END ADC1_Init 0 */
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
ADC_ChannelConfTypeDef sConfig = {0}; {
Error_Handler();
/* USER CODE BEGIN ADC1_Init 1 */ }
}
/* USER CODE END ADC1_Init 1 */
/**
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) * @brief ADC1 Initialization Function
*/ * @param None
hadc1.Instance = ADC1; * @retval None
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8; */
hadc1.Init.Resolution = ADC_RESOLUTION_12B; static void MX_ADC1_Init(void)
hadc1.Init.ScanConvMode = DISABLE; {
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE; /* USER CODE BEGIN ADC1_Init 0 */
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* USER CODE END ADC1_Init 0 */
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1; ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* USER CODE BEGIN ADC1_Init 1 */
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{ /* USER CODE END ADC1_Init 1 */
Error_Handler();
} /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. hadc1.Instance = ADC1;
*/ hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8;
sConfig.Channel = ADC_CHANNEL_0; hadc1.Init.Resolution = ADC_RESOLUTION_12B;
sConfig.Rank = 1; hadc1.Init.ScanConvMode = DISABLE;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; hadc1.Init.ContinuousConvMode = DISABLE;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) hadc1.Init.DiscontinuousConvMode = DISABLE;
{ hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
Error_Handler(); hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
} hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
/* USER CODE BEGIN ADC1_Init 2 */ hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
/* USER CODE END ADC1_Init 2 */ hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
} {
Error_Handler();
/** }
* @brief I2C1 Initialization Function
* @param None /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
* @retval None */
*/ sConfig.Channel = ADC_CHANNEL_0;
static void MX_I2C1_Init(void) sConfig.Rank = 1;
{ sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
/* USER CODE BEGIN I2C1_Init 0 */ {
Error_Handler();
/* USER CODE END I2C1_Init 0 */ }
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END ADC1_Init 2 */
/* USER CODE END I2C1_Init 1 */
hi2c1.Instance = I2C1; }
hi2c1.Init.ClockSpeed = 100000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; /**
hi2c1.Init.OwnAddress1 = 0; * @brief I2C1 Initialization Function
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; * @param None
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; * @retval None
hi2c1.Init.OwnAddress2 = 0; */
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; static void MX_I2C1_Init(void)
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; {
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{ /* USER CODE BEGIN I2C1_Init 0 */
Error_Handler();
} /* USER CODE END I2C1_Init 0 */
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END I2C1_Init 2 */
/* USER CODE END I2C1_Init 1 */
} hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000;
/** hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
* @brief RTC Initialization Function hi2c1.Init.OwnAddress1 = 0;
* @param None hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
* @retval None hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
*/ hi2c1.Init.OwnAddress2 = 0;
static void MX_RTC_Init(void) hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
{ hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
/* USER CODE BEGIN RTC_Init 0 */ {
Error_Handler();
/* USER CODE END RTC_Init 0 */ }
/* USER CODE BEGIN I2C1_Init 2 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0}; /* USER CODE END I2C1_Init 2 */
/* USER CODE BEGIN RTC_Init 1 */ }
/* USER CODE END RTC_Init 1 */ /**
* @brief RTC Initialization Function
/** Initialize RTC Only * @param None
*/ * @retval None
hrtc.Instance = RTC; */
hrtc.Init.HourFormat = RTC_HOURFORMAT_24; static void MX_RTC_Init(void)
hrtc.Init.AsynchPrediv = 127; {
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; /* USER CODE BEGIN RTC_Init 0 */
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; /* USER CODE END RTC_Init 0 */
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{ RTC_TimeTypeDef sTime = {0};
Error_Handler(); RTC_DateTypeDef sDate = {0};
}
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END RTC_Init 1 */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC Only
/** Initialize RTC and set the Time and Date */
*/ hrtc.Instance = RTC;
sTime.Hours = 0; hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
sTime.Minutes = 0; hrtc.Init.AsynchPrediv = 127;
sTime.Seconds = 0; hrtc.Init.SynchPrediv = 255;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET; hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK) hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
{ if (HAL_RTC_Init(&hrtc) != HAL_OK)
Error_Handler(); {
} Error_Handler();
sDate.WeekDay = RTC_WEEKDAY_MONDAY; }
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1; /* USER CODE BEGIN Check_RTC_BKUP */
sDate.Year = 0;
/* USER CODE END Check_RTC_BKUP */
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
{ /** Initialize RTC and set the Time and Date
Error_Handler(); */
} sTime.Hours = 0;
/* USER CODE BEGIN RTC_Init 2 */ sTime.Minutes = 0;
sTime.Seconds = 0;
/* USER CODE END RTC_Init 2 */ sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
} if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
{
/** Error_Handler();
* @brief GPIO Initialization Function }
* @param None sDate.WeekDay = RTC_WEEKDAY_MONDAY;
* @retval None sDate.Month = RTC_MONTH_JANUARY;
*/ sDate.Date = 1;
static void MX_GPIO_Init(void) sDate.Year = 0;
{
GPIO_InitTypeDef GPIO_InitStruct = {0}; if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
{
/* GPIO Ports Clock Enable */ Error_Handler();
__HAL_RCC_GPIOC_CLK_ENABLE(); }
__HAL_RCC_GPIOH_CLK_ENABLE(); /* USER CODE BEGIN RTC_Init 2 */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE(); /* USER CODE END RTC_Init 2 */
/*Configure GPIO pin Output Level */ }
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
/**
/*Configure GPIO pin : PC13 */ * @brief GPIO Initialization Function
GPIO_InitStruct.Pin = GPIO_PIN_13; * @param None
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; * @retval None
GPIO_InitStruct.Pull = GPIO_NOPULL; */
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; static void MX_GPIO_Init(void)
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); {
GPIO_InitTypeDef GPIO_InitStruct = {0};
}
/* GPIO Ports Clock Enable */
/* USER CODE BEGIN 4 */ __HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/* USER CODE END 4 */ __HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**
* @brief This function is executed in case of error occurrence. /*Configure GPIO pin Output Level */
* @retval None HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
*/
void Error_Handler(void) /*Configure GPIO pin : PC13 */
{ GPIO_InitStruct.Pin = GPIO_PIN_13;
/* USER CODE BEGIN Error_Handler_Debug */ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
/* User can add his own implementation to report the HAL error return state */ GPIO_InitStruct.Pull = GPIO_NOPULL;
__disable_irq(); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
while (1) HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
{
} }
/* USER CODE END Error_Handler_Debug */
} /* USER CODE BEGIN 4 */
#ifdef USE_FULL_ASSERT /* USER CODE END 4 */
/**
* @brief Reports the name of the source file and the source line number /**
* where the assert_param error has occurred. * @brief This function is executed in case of error occurrence.
* @param file: pointer to the source file name * @retval None
* @param line: assert_param error line source number */
* @retval None void Error_Handler(void)
*/ {
void assert_failed(uint8_t *file, uint32_t line) /* USER CODE BEGIN Error_Handler_Debug */
{ /* User can add his own implementation to report the HAL error return state */
/* USER CODE BEGIN 6 */ __disable_irq();
/* User can add his own implementation to report the file name and line number, while (1)
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ {
/* USER CODE END 6 */ }
} /* USER CODE END Error_Handler_Debug */
#endif /* USE_FULL_ASSERT */ }
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */