本帖最后由 shuibaihe0506 于 2015-8-5 14:05 编辑
1.现象:时钟芯片有时通信正常,有时无应答(示波器查应答管脚一直为高电平,检测不到低电平),原来测试正常的片子隔一段时间后不正常了,再重新操作有可能又恢复正常
3.一般情况下如芯片出现异常采取以下措施:
1)重新焊接芯片一般可以恢复正常,个别情况下需要把芯片焊下来重新焊接,当时可以正常使用,过一段时间后又不正常了
2)补焊晶振和匹配电容,
3)更换备用电池,
4)匹配电容原来用的是15PF,后来更换为9pf,仍然有上述现象
以上措施仅能使芯片当时恢复正常,隔一段时间后又有故障出现
驱动程序我看过了,没有问题,如果有问题的话补焊应该也不会起作用,到底是哪里出现问题了呢?求高手指点
程序
:/*****************************************************************/
/*文件名:PCF8563IIC.c
*整体描述:单片机硬件IIC软件,字节方式,主方式
* IIC接口:
*作者:
*状态: 通过
*****************************************************************/
#include "pcf8563.h"
#include "stm32f10x_lib.h"
/*-----------------/////////////////设置时间//////////////////-----------------------------*/
uint8 RTCSet(void)
{
if(!RTCWriteByte(0x08,Hex2Dcb(SysTime.Year[0]))) return 2;
if(!RTCWriteByte(0x07,Hex2Dcb(SysTime.Month))) return 2;
if(!RTCWriteByte(0x05,Hex2Dcb(SysTime.Date))) return 2;
if(!RTCWriteByte(0x02,Hex2Dcb(SysTime.Second))) return 2;
if(!RTCWriteByte(0x03,Hex2Dcb(SysTime.Minute))) return 2;
if(!RTCWriteByte(0x04,Hex2Dcb(SysTime.Hour))) return 2;
if(!RTCWriteByte(0x00,0)) return 2;
if(!RTCWriteByte(0x01,0x12)) return 2;//SET THE CONTROL AND STATUS REGISTER2
return 1;
}
/*------------------------------------------------------------
FUNC :
PARA :
RETRUN :
PARA DESCRI :
status : OK
data : 2005.09.07
COPYRIGHT : BITTYPHOON .BJKCSS
-------------------------------------------------------------*/
void RTCinitI2c(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
GPIO_InitStructure.GPIO_Pin = RTC_SDA_PIN | RTC_SCL_PIN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_RTC_DET, &GPIO_InitStructure);
}
void RTC_SDA_IN(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = RTC_SDA_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; /*这里一定要设成输入上拉,否则不能读出数据*/
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOB, &GPIO_InitStruct );
}
void RTC_SDA_OUT(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
GPIO_InitStruct.GPIO_Pin = RTC_SDA_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOB, &GPIO_InitStruct );
}
/*-------------------------------------------------------------
FUNC : write a Byte to the register or register of pcf8653
PARA : unsigned char RTCRegAddr,unsigned char data
RETRUN : NO
PARA DESCRI : RTCRegAddr, the addr of pcf8653 register ;
data: data to be writed
status : OK
data :
COPYRIGHT :
-------------------------------------------------------------*/
uint8 RTCWriteByte(unsigned char RTCRegAddr,unsigned char data)
{
RTCI2cStart();
if(!RTCI2cSendOneByte(0xA2)) return 0;
if(!RTCI2cSendOneByte(RTCRegAddr)) return 0;
if(!RTCI2cSendOneByte(data))return 0;
RTCI2cStop();
return 1;
}
/*------------------------------------------------------------
FUNC : read a data from the register of pcf8653
PARA : unsigned char RTCRegAddr
RETRUN : unsigned char data
PARA DESCRI : data; data read from the pcf8653 register
status :
data :
COPYRIGHT :
-------------------------------------------------------------*/
uint8 RTCReadByte(uint8 RTCRegAddr)
{
uint8 d_read=0;
RTCI2cStart();
RTCI2cSendOneByte(0xa2);
RTCI2cSendOneByte(RTCRegAddr);
RTCI2cStart();
RTCI2cSendOneByte(0xA3);
d_read=RTCI2cReceiveOneByte();
RTCI2cAckSend(1);
Delay(DELAY_TIME);
RTCI2cStop();
return(d_read);
}
/*------------------------------------------------------------
FUNC : produce the start signal for the i2c bus
PARA :
RETRUN :
PARA DESCRI :
status : OK
data :
COPYRIGHT :
-------------------------------------------------------------*/
void RTCI2cStart(void)
{
RTCinitI2c();
RTC_SDA_1;
RTC_SCL_1;
Delay(DELAY_TIME);
RTC_SDA_0;
Delay(DELAY_TIME);
RTC_SCL_0;
}
/*-----------------------------------------------------------
FUNC : i2c bus stop signal produce module
PARA : NO
PARA DESCRI : NO
status : OK
data :
COPYRIGHT :
--------------------------------------------------------------*/
void RTCI2cStop(void)
{
RTC_SDA_OUT();
RTC_SDA_0;
RTC_SCL_1;
Delay(DELAY_TIME);
RTC_SDA_1;
Delay(DELAY_TIME);
}
/*------------------------------------------------------------
FUNC : send one byte to the i2c bus
PARA : unsigned char data
RETRUN : NO
PARA DESCRI : data; data sent to the i2c bus
status : OK
data :
COPYRIGHT :
-----------------------------------------------------------*/
uint8 RTCI2cSendOneByte(unsigned char data)
{
char i=0;
RTC_SDA_OUT();
for(i=8;i>0;i--)
{
if(((data>>(i-1))&0x1)==0x1)
GPIO_SetBits ( GPIO_RTC_DET, RTC_SDA_PIN );
else
GPIO_ResetBits( GPIO_RTC_DET, RTC_SDA_PIN );
Delay(DELAY_TIME);
RTC_SCL_1;
Delay(DELAY_TIME);
RTC_SCL_0;
Delay(DELAY_TIME);
}
return RTCI2cAckCheck();
}
/*------------------------------------------------------------
FUNC : read a data from the i2c bus
PARA : no
RETRUN : unsigned char data
PARA DESCRI : data; data read from the i2c bus
status : OK!
data :
COPYRIGHT :
-----------------------------------------------------------*/
uint8 RTCI2cReceiveOneByte(void)
{
uint8 i=0;
uint8 data_1=0;
RTC_SDA_IN();
for(i=0;i<8;i++)
{
RTC_SCL_1;
Delay(DELAY_TIME);
data_1 |= ((GET_SDA_IN())<<(7-i));
Delay(DELAY_TIME);
RTC_SCL_0;
Delay(DELAY_TIME);
}
return(data_1);
}
uint8 GET_SDA_IN(void)
{
if(GPIO_ReadInputDataBit( GPIOB, RTC_SDA_PIN ))
return 1;
else
return 0;
}
/*--------------------------------------------------------------
FUNC : check the ack signal of slave i2c device
PARA : no
RETRUN : no
PARA DESCRI :
status : OK!
data : 2005.07.12
COPYRIGHT : BITTYPHOON .BJKCSS
---------------------------------------------------------------*/
uint8 RTCI2cAckCheck(void)
{
uint16 nError=0x7FFF;
RTC_SDA_IN();
RTC_SCL_1;
Delay(DELAY_TIME);//
while(GET_SDA_IN() ==1)//
{
nError--;
if(nError==0) {break; }
}
if(GET_SDA_IN() == 1)
nError = 0;
else
nError = 0x7fff;
RTC_SCL_0;
Delay(DELAY_TIME);
if(nError==0)
return NO;
else
return YES;
}
/*--------------------------------------------------------------
FUNC : check the ack signal of slave i2c device
PARA : no
RETRUN : no
PARA DESCRI :
status : OK!
data :
COPYRIGHT :
---------------------------------------------------------------*/
void RTCI2cAckSend(uint8 AckData)
{
RTC_SDA_OUT();
if(AckData==1)
GPIO_SetBits ( GPIO_RTC_DET, RTC_SDA_PIN );
else
if(AckData==0)
GPIO_ResetBits ( GPIO_RTC_DET, RTC_SDA_PIN );
Delay(DELAY_TIME);
RTC_SCL_1;
Delay(DELAY_TIME);
RTC_SCL_0;
}
uint8 Dec2Hex(uint8 dec)
{
uint8 temp0;
temp0 = (dec >> 4) *10;
dec &= 0x0f;
dec += temp0;
return dec;
}
uint8 Hex2Dcb(uint8 hex)
{
uint8 dcb;
dcb =((hex/10)<<4)+(hex%10);
return dcb;
}
void Delay(uint16 DelayTime)
{
uint16 i;
for (i = 0; i < DelayTime; i++)
{
}
}
|