HI, I am trying to use M41ST85W, and I cant initialize this RTC module.
Hi, I am Emily Ha.
For more than 1 month, I've try to use M41ST85W RTC Module.
However, I couldnt :(
Finially, I ask my problem to this web community site.
My Board : STM32F446RE
My RTC Module : M41ST85W
My deburging UI : Keil5
I made my code based on AN3060 Application note, and device's datasheet.
Based on this information, I wrote this.
First, I activated the I2C. (Below the line, you can find 'hi2c1'.)
And, I enabled the ST bit and halt bit.(Each bit is setted to 0.)
But,,,... there's nothing happened.
I cant even imagine what to do and how to do.
Plz, help me to use this RTC Module.
Which line is incorrect??? Which line should I rewrite??
#include "main.h"
#include "i2c.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
uint8_t I2C_Add_D0 = 0xd0;
uint8_t Sec_Value = 0;
uint8_t Clock_Addr_Halt_bit = 0x0c;
uint8_t clokck_haltbit_disalbe = 0x01<<6;
uint8_t clokck_haltbit_enalbe = 0x00<<6;
uint8_t Clock_Addr_Enalbe_bit = 0x01;
uint8_t clock_enalbe = 0x01<<7; // 00000000
uint8_t clock_disable = 0x00<<7; // 00000000
uint8_t Clock_Addr_Sec_init = 0x01;
uint8_t clock_sec_init = 0x04;
int second = 0;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
HAL_I2C_Mem_Write(&hi2c1, I2C_Add_D0, Clock_Addr_Halt_bit, I2C_MEMADD_SIZE_8BIT,&clokck_haltbit_enalbe, 1, 5000);
HAL_Delay(5000);
HAL_I2C_Mem_Write(&hi2c1, I2C_Add_D0, Clock_Addr_Enalbe_bit, I2C_MEMADD_SIZE_8BIT, &clock_disable, 8, 10);
HAL_Delay(10);
HAL_I2C_Mem_Write(&hi2c1, I2C_Add_D0, Clock_Addr_Sec_init, I2C_MEMADD_SIZE_8BIT, &clock_sec_init, 8, 10);
HAL_Delay(10);
//HAL_I2C_Mem_Write(&hi2c1, I2C_Add_D0, Clock_Addr_Enalbe_bit, I2C_MEMADD_SIZE_8BIT, &clock_enalbe, 8, 10);
//HAL_Delay(10);
HAL_I2C_Mem_Write(&hi2c1, I2C_Add_D0, Clock_Addr_Halt_bit, I2C_MEMADD_SIZE_8BIT,&clokck_haltbit_disalbe, 1, 5000);
HAL_Delay(5000);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
HAL_I2C_Mem_Read(&hi2c1, I2C_Add_D0, Clock_Addr_Sec_init, I2C_MEMADD_SIZE_8BIT, &Sec_Value, 8, 10);
HAL_Delay(10);
HAL_UART_Transmit(&huart2, &Sec_Value, I2C_MEMADD_SIZE_8BIT, 10);
HAL_Delay(1000);
//16??? Sec_Value? 10??? ??
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}