From 4c1eff0373b7a4a0072fc7515352139cd9d6d02f Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Mon, 16 May 2016 15:45:02 +0200 Subject: Add code to talk with the external RTC chip. --- stm-init.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'stm-init.c') diff --git a/stm-init.c b/stm-init.c index 2219d43..af3d47b 100644 --- a/stm-init.c +++ b/stm-init.c @@ -44,6 +44,9 @@ #ifdef HAL_UART_MODULE_ENABLED #include "stm-uart.h" #endif +#ifdef HAL_I2C_MODULE_ENABLED +#include "stm-rtc.h" +#endif /* Private variables ---------------------------------------------------------*/ @@ -55,6 +58,9 @@ static void MX_GPIO_Init(void); static void MX_USART1_UART_Init(void); static void MX_USART2_UART_Init(void); #endif +#ifdef HAL_I2C_MODULE_ENABLED +static void MX_I2C2_Init(void); +#endif void stm_init(void) { @@ -74,6 +80,9 @@ void stm_init(void) MX_USART1_UART_Init(); MX_USART2_UART_Init(); #endif +#ifdef HAL_I2C_MODULE_ENABLED + MX_I2C2_Init(); +#endif } @@ -138,6 +147,26 @@ static void MX_GPIO_Init(void) } #endif +#ifdef HAL_I2C_MODULE_ENABLED +/* I2C2 init function (external RTC chip) */ +void MX_I2C2_Init(void) +{ + hi2c_rtc.Instance = I2C2; + hi2c_rtc.Init.ClockSpeed = 10000; + hi2c_rtc.Init.DutyCycle = I2C_DUTYCYCLE_2; + hi2c_rtc.Init.OwnAddress1 = 0; /* Will operate as Master */ + hi2c_rtc.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + hi2c_rtc.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; + hi2c_rtc.Init.OwnAddress2 = 0; + hi2c_rtc.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; + hi2c_rtc.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; + + if (HAL_I2C_Init(&hi2c_rtc) != HAL_OK) { + Error_Handler(); + } +} +#endif + /** * @brief This function is executed in case of error occurrence. * @param None -- cgit v1.2.3