先上代码:
int PCF8563Read(unsigned char address,unsigned char *pbuf,int number)
{
int i;
//
// Specify slave address
// 0xA3 --> read
// 0xA2 --> write
//
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x51, false);
//
// Place the character to be sent in the data register
//
I2CMasterDataPut(I2C_MASTER_BASE,address);
//
// Initiate send of character from Master to Slave
//
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
//
// Delay until transmission completes
//
while(I2CMasterBusy(I2C_MASTER_BASE));
//指定从机地址
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x51, true);
//Initiate send character from Slave to Master
// 读取数据命令
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
//
// Delay until transmission completes
//
for(i = 0; i < number-1; i++)
{
while(I2CMasterBusy(I2C_MASTER_BASE));
*pbuf++ = (unsigned char)I2CMasterDataGet(I2C_MASTER_BASE);
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
}
//发送一个停止位
while(I2CMasterBusy(I2C_MASTER_BASE));
*pbuf++ = (unsigned char)I2CMasterDataGet(I2C_MASTER_BASE);
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusBusy(I2C_MASTER_BASE)); return i;
}
使用IIC外挂一个RTC:PCF8563T,程序运行了好几天,发现出现CPU停在最后的一个while循环(红色标志的语句)等待,请问这是什么问题引起的,硬件问题还是软件问题? |