cancel
Showing results for 
Search instead for 
Did you mean: 

HI, I am trying to use M41ST85W, and I cant initialize this RTC module.

EHa.1
Associate II

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 */
}

2 REPLIES 2
Eleon BORLINI
ST Employee

Hi Emily @EHa.1​ ,

I've added also the STM32F4 topic for more support, since the issue might come from the interface between the microcontroller and the RTC.

Did you start your code from scratch or did you use CubeMX tool or the F4 package for the STM32F446RE? An are you checking the I2C lines (both for the M41ST85W and for the MEMS, if you are using them) with an oscilloscope or doesn't your program work at all?

I suggest you to check the if the firmware package for X-CUBE-RTC, and in particular the AN4759 application note, if it can give you more suggestions. It's important you correctly set the clock tree in your application (the STM32CubeIDE could help you for this purpose).

-Eleon

Thanks for your reply :D

First of all, I've tried t o make my M41ST85W code using CubeMX.

Totally, I built by my self based STM datasheet and application note(AN3060).

And I tested MCU and M41ST85W module together.

I've read carefully the application note AN4759, but I use RTC module, not RTC in MCU.

So, I think there is little reference from that application note. :C

sorry to say that...

It is....so difficult

I am really appreciated your comment.