OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4222|回复: 11

RTC的问题

[复制链接]

16

主题

51

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2017-2-13
在线时间
23 小时
发表于 2017-4-12 07:40:11 | 显示全部楼层 |阅读模式
各路大神想求助一下RTC用串口显示该怎么设置呢?

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

50

主题

1805

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
6662
金钱
6662
注册时间
2016-5-29
在线时间
910 小时
发表于 2017-4-12 10:19:35 | 显示全部楼层
回复 支持 反对

使用道具 举报

23

主题

323

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1010
金钱
1010
注册时间
2016-11-8
在线时间
233 小时
发表于 2017-4-12 11:17:33 | 显示全部楼层

RTC时间 用串口打印 应该是这个意思~
亦余心之所善,
虽九死其犹未悔。
回复 支持 反对

使用道具 举报

50

主题

1805

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
6662
金钱
6662
注册时间
2016-5-29
在线时间
910 小时
发表于 2017-4-12 12:49:30 | 显示全部楼层
简单问题自己网上查.
回复 支持 反对

使用道具 举报

16

主题

51

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2017-2-13
在线时间
23 小时
 楼主| 发表于 2017-4-12 14:38:32 | 显示全部楼层
南有乔木 发表于 2017-4-12 11:17
RTC时间 用串口打印 应该是这个意思~

是的呢……怎么设置呢?
回复 支持 反对

使用道具 举报

16

主题

51

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2017-2-13
在线时间
23 小时
 楼主| 发表于 2017-4-12 14:39:52 | 显示全部楼层
操作系统 发表于 2017-4-12 12:49
简单问题自己网上查.

查了……还是没有解决……
回复 支持 反对

使用道具 举报

23

主题

323

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1010
金钱
1010
注册时间
2016-11-8
在线时间
233 小时
发表于 2017-4-12 14:57:42 | 显示全部楼层
萌萌哒的爱学者 发表于 2017-4-12 14:38
是的呢……怎么设置呢?

获取RTC各个状态:年 月 日 时 分 秒-->通过串口发送以上数字 -->串口助手查看即可~~

具体怎么操作实现,你自己试试,有啥问题再问
亦余心之所善,
虽九死其犹未悔。
回复 支持 反对

使用道具 举报

79

主题

399

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1845
金钱
1845
注册时间
2015-9-21
在线时间
565 小时
发表于 2017-4-12 15:04:29 | 显示全部楼层
既然都已经学习STM32了,像这种问题应该自己可以解决的!
回复 支持 反对

使用道具 举报

16

主题

51

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2017-2-13
在线时间
23 小时
 楼主| 发表于 2017-4-12 15:11:47 | 显示全部楼层
南有乔木 发表于 2017-4-12 14:57
获取RTC各个状态:年 月 日 时 分 秒-->通过串口发送以上数字 -->串口助手查看即可~~

具体怎么操作实 ...

#include "STM32F30x.h"  
#include "rtc.h"
#include "usart.h"
#include "stdio.h"

unsigned int TimingDelay;
unsigned char i=0,j=0;
unsigned char flag=0,flag1=0;
unsigned char showtime[50] = {0};
unsigned char showdate[50] = {0};
extern RTC_DateTypeDef RTC_DateStructure;
extern RTC_TimeTypeDef RTC_TimeStructure;

void GPIO_Config(void);
//void Delay(__IO uint32_t nTime);
int main(void)
{
        SysTick_Config(72000);
        RTC_Config();
        USART_Config();
  while (1)
  {       
       
                         /* Get the RTC current Time */
                                RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
                                /* Get the RTC current Date */
                                RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
                                /* Display time Format : hh:mm:ss */
                                sprintf((char*)showtime,"%.2d:%.2d:%.2d",RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
                                /* Display date Format : mm-dd-yy */
                                sprintf((char*)showdate,"%.2d-%.2d-%.2d",RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date, 2000 + RTC_DateStructure.RTC_Year);        
                                PrintCom(USART1, "当前时间为:\r\n");       
                                PrintCom(USART1, showdate);
                                PrintCom(USART1, "\r\n");
                                PrintCom(USART1, showtime);
                                PrintCom(USART1, "\r\n");
//                               
//                }
//                       
//                if(flag1==1)
//                {
//                                flag1=0;
//                         /* Get the RTC current Time */
//                                RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
//                                /* Get the RTC current Date */
//                                RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
//                                /* Display time Format : hh:mm:ss */
//                                sprintf((char*)showtime,"%.2d:%.2d:%.2d",RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
//                                /* Display date Format : mm-dd-yy */
//                                sprintf((char*)showdate,"%.2d-%.2d-%.2d",RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date, 2000 + RTC_DateStructure.RTC_Year);        
//                               
//                                PrintCom(USART1, showtime);
//                                PrintCom(USART1, "\r\n");
//                                PrintCom(USART1, showdate);
//                                PrintCom(USART1, "\r\n");
//                }
//  }


//void Delay(__IO uint32_t nTime)//滴答定时精确定时
//{
//  TimingDelay = nTime;
//  
//  while(TimingDelay != 0);
//}

}

}


RTC的代码
#include <stm32f30x.h>

#include "rtc.h"

RTC_DateTypeDef RTC_DateStructure;
RTC_TimeTypeDef RTC_TimeStructure;

void RTC_Config(void)
{
  RTC_InitTypeDef RTC_InitStructure;
  RTC_AlarmTypeDef RTC_AlarmStructure;  
  NVIC_InitTypeDef NVIC_InitStructure;
  EXTI_InitTypeDef EXTI_InitStructure;

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to Backup */
  PWR_BackupAccessCmd(ENABLE);

  /* Reset RTC Domain */
  RCC_BackupResetCmd(ENABLE);
  RCC_BackupResetCmd(DISABLE);

  /* Allow access to RTC */
  PWR_BackupAccessCmd(ENABLE);

  /* Enable the LSE OSC */
//  RCC_LSEConfig(RCC_LSE_ON);
       
        /* Enable the LSI OSC */
        RCC_LSICmd(ENABLE);

  /* Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {}

  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);

  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();

  /* Calendar Configuration */
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  RTC_InitStructure.RTC_SynchPrediv        =  0x120; /* (37KHz / 128) - 1 = 0x120*/
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);  

  /* Set the alarm 01h:00min:04s */
  RTC_AlarmStructure.RTC_AlarmTime.RTC_H12     = RTC_H12_AM;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours   = 0x10;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 0x10;
  RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x00;
  RTC_AlarmStructure.RTC_AlarmDateWeekDay = RTC_Weekday_Monday;
  RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_Weekday_Monday;
  /* Alarm mask hour, min and second:default Alarm generation each 1s */
  RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
  RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);

  /* Enable RTC Alarm A Interrupt */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);

  /* Enable the alarm */
  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

  /* Set the date: Wednesday February 5th 2014 */
  RTC_DateStructure.RTC_Year = 14;
  RTC_DateStructure.RTC_Month = RTC_Month_August;
  RTC_DateStructure.RTC_Date = 0x25;
  RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Monday;
  RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);

  /* Set the time to 01h 00mn 00s AM */
  RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
  RTC_TimeStructure.RTC_Hours   = 0x10;
  RTC_TimeStructure.RTC_Minutes = 0x09;
  RTC_TimeStructure.RTC_Seconds = 0x00;
  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);   

  RTC_ClearFlag(RTC_FLAG_ALRAF);

  /* RTC Alarm A Interrupt Configuration */
  /* EXTI configuration */
  EXTI_ClearITPendingBit(EXTI_Line17);
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable the RTC Alarm Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure); ;
}



串口的代码

#include <stm32f30x.h>

#include "usart.h"

void USART_Config(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
                USART_InitTypeDef USART_InitStructure;
                NVIC_InitTypeDef NVIC_InitStructure;
         
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
                RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);

                //USARTx_TX   GPIO_Mode_AF_PP
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
                GPIO_Init(GPIOA , &GPIO_InitStructure);               
               
                //USARTx_RX   GPIO_Mode_AF_PP & IPU
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;               
                GPIO_Init(GPIOA, &GPIO_InitStructure);
               
                GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);
                GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);
               
                GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);
                GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);

                NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
                NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
                NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
                NVIC_Init(&NVIC_InitStructure);       

                USART_InitStructure.USART_BaudRate = 9600;
                USART_InitStructure.USART_WordLength = USART_WordLength_8b;
                USART_InitStructure.USART_StopBits = USART_StopBits_1;
                USART_InitStructure.USART_Parity = USART_Parity_No;
                USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
                USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART1, &USART_InitStructure);

    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    USART_Cmd(USART1, ENABLE);
}

void PrintCom(USART_TypeDef* USARTx, uint8_t *Data)
{
       
                while(*Data)
                {
                        USART_SendData(USARTx, *Data++);
                        while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
                }                                                                                                       
}




回复 支持 反对

使用道具 举报

16

主题

51

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2017-2-13
在线时间
23 小时
 楼主| 发表于 2017-4-12 15:12:28 | 显示全部楼层
硕果累累 发表于 2017-4-12 15:04
既然都已经学习STM32了,像这种问题应该自己可以解决的!

学的不好
回复 支持 反对

使用道具 举报

16

主题

51

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2017-2-13
在线时间
23 小时
 楼主| 发表于 2017-4-12 15:13:15 | 显示全部楼层
南有乔木 发表于 2017-4-12 14:57
获取RTC各个状态:年 月 日 时 分 秒-->通过串口发送以上数字 -->串口助手查看即可~~

具体怎么操作实 ...

能帮忙看一下这样行么?代码已经贴在下面了……编译通过,但是不知道能不能用……
回复 支持 反对

使用道具 举报

23

主题

323

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1010
金钱
1010
注册时间
2016-11-8
在线时间
233 小时
发表于 2017-4-12 15:36:52 | 显示全部楼层
萌萌哒的爱学者 发表于 2017-4-12 15:13
能帮忙看一下这样行么?代码已经贴在下面了……编译通过,但是不知道能不能用……

有样板的话可以跑跑试试啊 ,一步步调试着来,发现问题解决问题


我这样单独看,也看不出个啥来
亦余心之所善,
虽九死其犹未悔。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-8-22 06:45

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表