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;
}
|