如何用I2C通信向指定存储空间写入指定字节的数据,想要往时钟芯片上写初始的时分秒数据,但是总是写不进去,想要请教一下各位大神。
是否是要使用这个函数?
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
然后用如下几个量进行组合呢?
#define I2C_MASTER_CMD_BURST_SEND_START 0x00000003
#define I2C_MASTER_CMD_BURST_SEND_CONT 0x00000001
#define I2C_MASTER_CMD_BURST_SEND_FINISH 0x00000005
Xupeng(FAA) He:
我来给你个例子吧,我是向地址为sla的从机中的地址为suba的寄存器写入数据s。
static void ADE7878_SetReg32(short sla,int suba,long s) { I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, sla, false);//false=wright I2CMasterDataPut(I2C0_MASTER_BASE, (suba>>8)&0x00ff); I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START); while(I2CMasterBusy(I2C0_MASTER_BASE)){} I2CMasterDataPut(I2C0_MASTER_BASE, suba&0x00ff); I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT); while(I2CMasterBusy(I2C0_MASTER_BASE)){} I2CMasterDataPut(I2C0_MASTER_BASE, (s>>24)&0x00ff); I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT); while(I2CMasterBusy(I2C0_MASTER_BASE)){} I2CMasterDataPut(I2C0_MASTER_BASE, (s>>16)&0x00ff); I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT); while(I2CMasterBusy(I2C0_MASTER_BASE)){} I2CMasterDataPut(I2C0_MASTER_BASE, (s>>8)&0x00ff); I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT); while(I2CMasterBusy(I2C0_MASTER_BASE)){} I2CMasterDataPut(I2C0_MASTER_BASE, s&0x00ff); I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusy(I2C0_MASTER_BASE)){} // Delay until transmission completes}
这个代码是亲测过的,希望对你有帮助。