专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
PCF8563 40秒出现跳变
2019-07-20 19:59
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
5924
8
1798
用IO口模拟I2C 外面接3.3V 4.7K的上拉电阻,现在出现20秒和40秒的时候小时和日期开始出现跳变。而回到0秒的时候又正常,有人遇到同样的问题吗?
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
8条回答
sapoiuyt
2019-07-21 11:35
void I2C_GPIO_Config(void)
{
uint8_t i;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = I2C_SCL|I2C_SDA;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
u8 PCF8563_SetDate(u8 PCF_Format, RTC_DateTypeDef* PCF_DataStruct)
{
RTC_DateTypeDef SetDate_Stu;
u8 ret = TRUE;
if(PCF_Format == PCF_Format_HEX) // 16进制
{
// 转换BCD 码
SetDate_Stu.RTC_Year = RTC_HexToBcd(PCF_DataStruct->RTC_Year);
SetDate_Stu.RTC_Month = RTC_HexToBcd(PCF_DataStruct->RTC_Month);
SetDate_Stu.RTC_Date = RTC_HexToBcd(PCF_DataStruct->RTC_Date);
SetDate_Stu.RTC_WeekDay = RTC_HexToBcd(PCF_DataStruct->RTC_WeekDay);
}
else if(PCF_Format == PCF_Format_BCD) // BCD 码
{
SetDate_Stu.RTC_Year = (PCF_DataStruct->RTC_Year);
SetDate_Stu.RTC_Month = (PCF_DataStruct->RTC_Month);
SetDate_Stu.RTC_Date = (PCF_DataStruct->RTC_Date);
SetDate_Stu.RTC_WeekDay = (PCF_DataStruct->RTC_WeekDay);
}
// 写进PCF8563
ret = Rtc8563Write(PCF8563_Address_Years,SetDate_Stu.RTC_Year);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Months,SetDate_Stu.RTC_Month);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Days,SetDate_Stu.RTC_Date);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_WeekDays,SetDate_Stu.RTC_WeekDay);
if(ret == FALSE)
goto ERROR;
return TRUE;
ERROR:
return FALSE;
}
u8 PCF8563_SetTime(u8 PCF_Format, RTC_TimeTypeDef* PCF_TimeStruct)
{
RTC_TimeTypeDef SetTime_Stu;
u8 ret = TRUE;
if(PCF_Format == PCF_Format_HEX) // 16进制
{
// 转换BCD 码
SetTime_Stu.RTC_Hours = RTC_HexToBcd(PCF_TimeStruct->RTC_Hours);
SetTime_Stu.RTC_Minutes = RTC_HexToBcd(PCF_TimeStruct->RTC_Minutes);
SetTime_Stu.RTC_Seconds = RTC_HexToBcd(PCF_TimeStruct->RTC_Seconds);
}
else if(PCF_Format == PCF_Format_BCD) // BCD 码
{
SetTime_Stu.RTC_Hours = (PCF_TimeStruct->RTC_Hours);
SetTime_Stu.RTC_Minutes = (PCF_TimeStruct->RTC_Minutes);
SetTime_Stu.RTC_Seconds = (PCF_TimeStruct->RTC_Seconds);
}
// 写进PCF8563
ret = Rtc8563Write(PCF8563_Alarm_Hours,SetTime_Stu.RTC_Hours);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Minutes,SetTime_Stu.RTC_Minutes);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Seconds,SetTime_Stu.RTC_Seconds);
if(ret == FALSE)
goto ERROR;
return TRUE;
ERROR:
return FALSE;
}
u8 PCF8563_GetDate(u8 PCF_Format, RTC_DateTypeDef* PCF_DataStruct)
{
/*
PCF_DataStruct->RTC_Years = Rtc8563Read(PCF8563_Address_Years);
PCF_DataStruct->RTC_Months= Rtc8563Read(PCF8563_Address_Months);
PCF_DataStruct->RTC_Days= Rtc8563Read(PCF8563_Address_Days);
PCF_DataStruct->RTC_WeekDays= Rtc8563Read(PCF8563_Address_WeekDays);
*/
PCF_DataStruct->RTC_Year= Rtc8563Read(PCF8563_Address_Years);
PCF_DataStruct->RTC_Month= Rtc8563Read(PCF8563_Address_Months);
PCF_DataStruct->RTC_Date= Rtc8563Read(PCF8563_Address_Days);
// PCF_DataStruct->RTC_WeekDay= Rtc8563Read(PCF8563_Address_WeekDays);
if(PCF_Format == PCF_Format_HEX)
{
// 转回16进制
PCF_DataStruct->RTC_Year = ((PCF_DataStruct->RTC_Year>>4)*10) + (PCF_DataStruct->RTC_Year&0x0F);
PCF_DataStruct->RTC_Month = ((PCF_DataStruct->RTC_Month>>4)*10) + (PCF_DataStruct->RTC_Month&0x0F);
PCF_DataStruct->RTC_Date = ((PCF_DataStruct->RTC_Date>>4)*10) + (PCF_DataStruct->RTC_Date&0x0F);
PCF_DataStruct->RTC_WeekDay = ((PCF_DataStruct->RTC_WeekDay>>4)*10) + (PCF_DataStruct->RTC_WeekDay&0x0F);
}
}
u8 PCF8563_GetTime(u8 PCF_Format, RTC_TimeTypeDef* PCF_TimeStruct)
{
PCF_TimeStruct->RTC_Hours = Rtc8563Read(PCF8563_Address_Hours);
PCF_TimeStruct->RTC_Minutes = Rtc8563Read(PCF8563_Address_Minutes);
PCF_TimeStruct->RTC_Seconds = Rtc8563Read(PCF8563_Address_Seconds);
UART6_SendByte(PCF_TimeStruct->RTC_Hours);
UART6_SendByte(PCF_TimeStruct->RTC_Minutes);
UART6_SendByte(PCF_TimeStruct->RTC_Seconds);
if(PCF_Format == PCF_Format_HEX)
{
// 转回16进制
PCF_TimeStruct->RTC_Hours = ((PCF_TimeStruct->RTC_Hours>>4)*10) + (PCF_TimeStruct->RTC_Hours&0x0F);
PCF_TimeStruct->RTC_Minutes = ((PCF_TimeStruct->RTC_Minutes>>4)*10) + (PCF_TimeStruct->RTC_Minutes&0x0F);
PCF_TimeStruct->RTC_Seconds = ((PCF_TimeStruct->RTC_Seconds>>4)*10) + (PCF_TimeStruct->RTC_Seconds&0x0F);
}
}
加载中...
查看其它8个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
void I2C_GPIO_Config(void)
{
uint8_t i;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = I2C_SCL|I2C_SDA;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
u8 PCF8563_SetDate(u8 PCF_Format, RTC_DateTypeDef* PCF_DataStruct)
{
RTC_DateTypeDef SetDate_Stu;
u8 ret = TRUE;
if(PCF_Format == PCF_Format_HEX) // 16进制
{
// 转换BCD 码
SetDate_Stu.RTC_Year = RTC_HexToBcd(PCF_DataStruct->RTC_Year);
SetDate_Stu.RTC_Month = RTC_HexToBcd(PCF_DataStruct->RTC_Month);
SetDate_Stu.RTC_Date = RTC_HexToBcd(PCF_DataStruct->RTC_Date);
SetDate_Stu.RTC_WeekDay = RTC_HexToBcd(PCF_DataStruct->RTC_WeekDay);
}
else if(PCF_Format == PCF_Format_BCD) // BCD 码
{
SetDate_Stu.RTC_Year = (PCF_DataStruct->RTC_Year);
SetDate_Stu.RTC_Month = (PCF_DataStruct->RTC_Month);
SetDate_Stu.RTC_Date = (PCF_DataStruct->RTC_Date);
SetDate_Stu.RTC_WeekDay = (PCF_DataStruct->RTC_WeekDay);
}
// 写进PCF8563
ret = Rtc8563Write(PCF8563_Address_Years,SetDate_Stu.RTC_Year);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Months,SetDate_Stu.RTC_Month);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Days,SetDate_Stu.RTC_Date);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_WeekDays,SetDate_Stu.RTC_WeekDay);
if(ret == FALSE)
goto ERROR;
return TRUE;
ERROR:
return FALSE;
}
u8 PCF8563_SetTime(u8 PCF_Format, RTC_TimeTypeDef* PCF_TimeStruct)
{
RTC_TimeTypeDef SetTime_Stu;
u8 ret = TRUE;
if(PCF_Format == PCF_Format_HEX) // 16进制
{
// 转换BCD 码
SetTime_Stu.RTC_Hours = RTC_HexToBcd(PCF_TimeStruct->RTC_Hours);
SetTime_Stu.RTC_Minutes = RTC_HexToBcd(PCF_TimeStruct->RTC_Minutes);
SetTime_Stu.RTC_Seconds = RTC_HexToBcd(PCF_TimeStruct->RTC_Seconds);
}
else if(PCF_Format == PCF_Format_BCD) // BCD 码
{
SetTime_Stu.RTC_Hours = (PCF_TimeStruct->RTC_Hours);
SetTime_Stu.RTC_Minutes = (PCF_TimeStruct->RTC_Minutes);
SetTime_Stu.RTC_Seconds = (PCF_TimeStruct->RTC_Seconds);
}
// 写进PCF8563
ret = Rtc8563Write(PCF8563_Alarm_Hours,SetTime_Stu.RTC_Hours);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Minutes,SetTime_Stu.RTC_Minutes);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Seconds,SetTime_Stu.RTC_Seconds);
if(ret == FALSE)
goto ERROR;
return TRUE;
ERROR:
return FALSE;
}
u8 PCF8563_GetDate(u8 PCF_Format, RTC_DateTypeDef* PCF_DataStruct)
{
/*
PCF_DataStruct->RTC_Years = Rtc8563Read(PCF8563_Address_Years);
PCF_DataStruct->RTC_Months= Rtc8563Read(PCF8563_Address_Months);
PCF_DataStruct->RTC_Days= Rtc8563Read(PCF8563_Address_Days);
PCF_DataStruct->RTC_WeekDays= Rtc8563Read(PCF8563_Address_WeekDays);
*/
PCF_DataStruct->RTC_Year= Rtc8563Read(PCF8563_Address_Years);
PCF_DataStruct->RTC_Month= Rtc8563Read(PCF8563_Address_Months);
PCF_DataStruct->RTC_Date= Rtc8563Read(PCF8563_Address_Days);
// PCF_DataStruct->RTC_WeekDay= Rtc8563Read(PCF8563_Address_WeekDays);
if(PCF_Format == PCF_Format_HEX)
{
// 转回16进制
PCF_DataStruct->RTC_Year = ((PCF_DataStruct->RTC_Year>>4)*10) + (PCF_DataStruct->RTC_Year&0x0F);
PCF_DataStruct->RTC_Month = ((PCF_DataStruct->RTC_Month>>4)*10) + (PCF_DataStruct->RTC_Month&0x0F);
PCF_DataStruct->RTC_Date = ((PCF_DataStruct->RTC_Date>>4)*10) + (PCF_DataStruct->RTC_Date&0x0F);
PCF_DataStruct->RTC_WeekDay = ((PCF_DataStruct->RTC_WeekDay>>4)*10) + (PCF_DataStruct->RTC_WeekDay&0x0F);
}
}
u8 PCF8563_GetTime(u8 PCF_Format, RTC_TimeTypeDef* PCF_TimeStruct)
{
PCF_TimeStruct->RTC_Hours = Rtc8563Read(PCF8563_Address_Hours);
PCF_TimeStruct->RTC_Minutes = Rtc8563Read(PCF8563_Address_Minutes);
PCF_TimeStruct->RTC_Seconds = Rtc8563Read(PCF8563_Address_Seconds);
UART6_SendByte(PCF_TimeStruct->RTC_Hours);
UART6_SendByte(PCF_TimeStruct->RTC_Minutes);
UART6_SendByte(PCF_TimeStruct->RTC_Seconds);
if(PCF_Format == PCF_Format_HEX)
{
// 转回16进制
PCF_TimeStruct->RTC_Hours = ((PCF_TimeStruct->RTC_Hours>>4)*10) + (PCF_TimeStruct->RTC_Hours&0x0F);
PCF_TimeStruct->RTC_Minutes = ((PCF_TimeStruct->RTC_Minutes>>4)*10) + (PCF_TimeStruct->RTC_Minutes&0x0F);
PCF_TimeStruct->RTC_Seconds = ((PCF_TimeStruct->RTC_Seconds>>4)*10) + (PCF_TimeStruct->RTC_Seconds&0x0F);
}
}
一周热门 更多>