Remove DS3231

I made a mistake while initialising the internal RTC (with RC instead of external crystal) so it was super unprecise
This commit is contained in:
2023-09-05 11:01:15 +02:00
parent 41fc9955c0
commit 7b25cf55ac
6 changed files with 107 additions and 2483 deletions

View File

@@ -10,14 +10,13 @@
#include "debug.h"
extern RTC_HandleTypeDef hrtc;
extern I2C_HandleTypeDef hi2c1;
void app_main(void *argument)
{
ts utc;
ts rtc;
//ts rtc;
ts local;
ts diff;
//ts diff;
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
uint8_t sBefore;
@@ -28,14 +27,11 @@ void app_main(void *argument)
debugln("LWIP is initialized");
DS3231_Init(&hi2c1);
debugln("DS3231 is initialized");
// The stored time is always in UTC
breakTime(NTPToEpochUnix(), &utc, 0);
toTimeZone(&utc, &local, UTC_DELTA_HOURS, 1);
debugln("Started: %02d:%02d:%02d", utc.Hour, utc.Minute, utc.Second);
debugln(" \n \n \n"); // I don't know why, but my uart/Serial monitor doesn't show epoch and packet sent if I remove the spaces
debugln(" \n"); // I don't know why, but my uart/Serial monitor doesn't show epoch and packet sent if I remove the spaces
Ts_To_RTC(&utc, &sTime, &sDate);
Set_Time(sTime, sDate);
DS3231_SetTime(&utc);
@@ -52,26 +48,26 @@ void app_main(void *argument)
for (;;)
{
Get_Time(&sDate, &sTime);
DS3231_GetTime(&utc);
//DS3231_GetTime(&utc);
if ((utc.Hour == 0) && (utc.Minute == 0) && (utc.Second == 0) && sBefore == 59)
{
debugln(" \nUpdating time");
breakTime(NTPToEpochUnix(), &utc, 0);
printf(" \n \n \n \n");
printf(" \n");
Ts_To_RTC(&utc, &sTime, &sDate);
Set_Time(sTime, sDate);
DS3231_SetTime(&utc);
//DS3231_SetTime(&utc);
}
RTC_To_Ts(&sTime, &sDate, &rtc);
RTC_To_Ts(&sTime, &sDate, &utc);
toTimeZone(&utc, &local, UTC_DELTA_HOURS, 1);
if (local.Second != sBefore)
{
printf(CURSOR_PREV_N_LINES(3) ERASE_FROM_CURSOR_TO_END);
debugln("RTC : %02d:%02d:%02d", sTime.Hours, sTime.Minutes, sTime.Seconds);
printf(CURSOR_PREV_N_LINES(1) ERASE_FROM_CURSOR_TO_END);
//debugln("RTC : %02d:%02d:%02d", sTime.Hours, sTime.Minutes, sTime.Seconds);
debugln("DS3231: %02d:%02d:%02d", utc.Hour, utc.Minute, utc.Second);
TimeDiff(&utc, &rtc, &diff);
debugln("DIFF : %02d:%02d:%02d", diff.Hour, diff.Minute, diff.Second);
//TimeDiff(&utc, &rtc, &diff);
//debugln("DIFF : %02d:%02d:%02d", diff.Hour, diff.Minute, diff.Second);
BSP_LCD_Clear(LCD_COLOR_TRANSPARENT);
Clock_Write_Date(0, 0, Y_CENTER, 40, local.Wday, local.Day, local.Month, local.Year + 1970);

View File

@@ -45,8 +45,6 @@
DMA2D_HandleTypeDef hdma2d;
I2C_HandleTypeDef hi2c1;
LTDC_HandleTypeDef hltdc;
RTC_HandleTypeDef hrtc;
@@ -68,7 +66,6 @@ static void MX_USART1_UART_Init(void);
static void MX_DMA2D_Init(void);
static void MX_FMC_Init(void);
static void MX_RTC_Init(void);
static void MX_I2C1_Init(void);
void app_main(void const * argument);
/* USER CODE BEGIN PFP */
@@ -113,7 +110,6 @@ int main(void)
MX_DMA2D_Init();
MX_FMC_Init();
MX_RTC_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
ip_addr_t ip;
/* set the default dns server for the NTP client*/
@@ -285,54 +281,6 @@ static void MX_DMA2D_Init(void)
}
/**
* @brief I2C1 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C1_Init(void)
{
/* USER CODE BEGIN I2C1_Init 0 */
/* USER CODE END I2C1_Init 0 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END I2C1_Init 1 */
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x00C0EAFF;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}
/**
* @brief LTDC Initialization Function
* @param None

View File

@@ -122,83 +122,6 @@ void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)
}
/**
* @brief I2C MSP Initialization
* This function configures the hardware resources used in this example
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(hi2c->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspInit 0 */
/* USER CODE END I2C1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
PeriphClkInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
__HAL_RCC_GPIOB_CLK_ENABLE();
/**I2C1 GPIO Configuration
PB8 ------> I2C1_SCL
PB9 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C1_CLK_ENABLE();
/* USER CODE BEGIN I2C1_MspInit 1 */
/* USER CODE END I2C1_MspInit 1 */
}
}
/**
* @brief I2C MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
{
if(hi2c->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspDeInit 0 */
/* USER CODE END I2C1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_I2C1_CLK_DISABLE();
/**I2C1 GPIO Configuration
PB8 ------> I2C1_SCL
PB9 ------> I2C1_SDA
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
/* USER CODE BEGIN I2C1_MspDeInit 1 */
/* USER CODE END I2C1_MspDeInit 1 */
}
}
/**
* @brief LTDC MSP Initialization
* This function configures the hardware resources used in this example