我把I2C的从机地址为0x60,要读的寄存器为0xb0,如何写I2C的代码才能从0xb0中读取出值?????
Michael Sun:
I2CMasterSlaveAddrSet这个就可以设置从机地址。
您指的读的是I2C从器件的寄存器0xb0吧。
这个要根据I2C从器件的时序来写。
X tank:
回复 Michael Sun:
ID就是slaveaddress,REG_ADDR就是寄存器地址,这样对不对???
I2CMasterSlaveAddrSet(I2C_BASE,ID,false); //查询忙与错误 while(I2CMasterBusBusy(I2C_BASE)); I2CMasterDataPut(I2C_BASE,REG_ADDR); I2CMasterControl(I2C_BASE,I2C_MASTER_CMD_SINGLE_SEND); while(I2CMasterBusy(I2C_BASE)); I2CMasterSlaveAddrSet(I2C_BASE,ID,true); I2CMasterControl(I2C_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE); while(I2CMasterBusy(I2C_BASE)); switch(I2CMasterErr(I2C_BASE)) { case I2C_MASTER_ERR_NONE: { // //I2CMasterControl(I2C_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE); //while(I2CMasterBusy(I2C_BASE)); DATA = I2CMasterDataGet(I2C_BASE);
return DATA; };break; case I2C_MASTER_ERR_ADDR_ACK:XX7299A_I2CRead(I2C_BASE,REG_ADDR,ID);break; case I2C_MASTER_ERR_DATA_ACK:XX7299A_I2CRead(I2C_BASE,REG_ADDR,ID);break; case I2C_MASTER_ERR_ARB_LOST:XX7299A_I2CRead(I2C_BASE,REG_ADDR,ID);break; default:return 100; }
X tank:
回复 Michael Sun:
我的是与XX7299A按键显示芯片通信