This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

我用I2C给OPT3001光照寄存器通讯,可以读取寄存器的值,但是通过I2C写寄存器的值的时候,发现写不进去,用示波器扎的时候,发现有从机地址0x44和寄存器地址0x01,没发现有要写的寄存器的值。

Other Parts Discussed in Thread: OPT3001

我用I2C给OPT3001光照寄存器通讯,可以读取寄存器的值,但是通过I2C写寄存器的值的时候,发现写不进去,用示波器扎的时候,发现有从机地址0x44和寄存器地址0x01,没发现有要写的寄存器的值。

  • 写的的数据测不到?写的方式是否正确,先发个简单的数据看能否测到信号
  • RX6110时间芯片写是没问题的,我写的可以自己读出来,但是在示波器上还是看不到具体写的值,只能看到从机地址和寄存器地址。。。很奇怪。OPT3001光照芯片连写都写不进去。。。
  • 写函数应该是没有问题的,这是写16位的寄存器,我用RX6110时间芯片写进去再读出来是没问题的,用这个OPT3001光照芯片,给01寄存器写0x54,0x10,再读出来是寄存器的默认值C810

    void SET_OPT3001_Register()
    {
    memset(txBuffer, 0, sizeof(txBuffer));
    memset(rxBuffer, 0xAA, sizeof(rxBuffer));
    txBuffer[0] = 0x54;txBuffer[1] = 0x10;
    HalSensorRWReg_OPT3001(0x01,txBuffer,2, rxBuffer, 0, 0x44);
    }

    bool HalSensorRWReg_OPT3001(uint8_t addr, uint8_t *pWriteBuf, uint8_t WriteBytes, uint8_t *pReadBuf, uint8_t ReadBytes, uint8_t slaveAddress)
    {
    Task_sleep(100 / Clock_tickPeriod);
    uint8_t tmp[32];//receiver buffer
    memcpy(tmp, txBuffer, WriteBytes);
    txBuffer[0] = addr;//address is device ID
    memcpy(txBuffer+1, tmp, WriteBytes);
    i2cTrans.writeCount = 1+WriteBytes;
    i2cTrans.writeBuf = txBuffer;
    i2cTrans.readCount = ReadBytes;
    i2cTrans.readBuf = rxBuffer;
    i2cTrans.slaveAddress = slaveAddress;

    I2C_transfer(handle, &i2cTrans);

    return 0;
    }
  • 找到一个OPT3001的例程,参考dev.ti.com/.../node