大家好,我正在尝试通过 I2C 从 LTC4151获取电压数据,我似乎无法再获取这些数据。 我正在使用 TI 外设驱动程序库,每当我尝试从设备读取数据时,即使电路有电压,我的值也会为0。 我有一个定制板。 下面是代码,并在尝试读取后注册数据。
要从设备读取的代码(为 I2CMasterControl()尝试了许多不同的参数,似乎没有任何改变):
void ReadInputVoltageMonitor( void ){
//read from the specified slave device
I2CMasterSlaveAddrSet(I2C0_BASE, 0xde, false);
//send control byte and read from the register from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE)){
}
//put the target register addres into data send register.
I2CMasterDataPut(I2C0_BASE, 0x02);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE)){
}
//read from the specified slave device
I2CMasterSlaveAddrSet(I2C0_BASE, 0xde, true);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C0_BASE)){
}
voltageValue = ((I2CMasterDataGet(I2C0_BASE) << 4) & 0xff0);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C0_BASE)){
}
voltageValue |= (I2CMasterDataGet(I2C0_BASE) & 0x0f);
while(I2CMasterBusy(I2C0_BASE)){
}
}
I2C 在该方法的末尾注册值:

LTC4151的地址信息(图像1是设备地址,图像2是寄存器地址)


阅读 LTC4151数据表中描述的操作步骤:
Read Protocol The master begins a read operation with a Start condition followed by the seven bit slave address and the R/W bit set to zero. After the addressed LTC4151 acknowledges the address byte, the master then sends a command byte that indicates which internal register the master wishes to read. The LTC4151 acknowledges this and then latches the lower three bits of the command byte into its internal register address pointer. The master then sends a repeated Start condition followed by the same seven bit address with the R/W bit now set to one. The LTC4151 acknowledges and sends the contents of the requested register. The transmission terminates when the master sends a Stop condition. If the master acknowledges the transmitted data byte, as in a Read Word command, the LTC4151 will send the contents of the next register. If the master acknowledges the second data byte and each of the following (if more) data bytes, as in a Read Page command, the LTC4151 will keep sending out each data byte in the register that corresponds to the incrementing register pointer. The read operation terminates and the register address pointer resets to 00h when the master sends a Stop condition.
我获得的数据始终为0,从寄存器值中可以看到,我收到了一个 nack 中断,据我所知,这意味着没有任何设备确认 I2C0总线上的地址。 我还无法理解如何使用数据表中描述的接收和发送条件,因为第一步是使用注册地址发送数据,但我正在执行读取操作。 此外,我假设使用地址0xde 并将 bReceive 标志设置为 false / true,在 I2CMasterSlaveAddrSet()中,根据规范将正确设置 LTC4151设备上的 R/W 引脚。
任何帮助都将受到极大的赞赏,因为我知道我应该从该设备中获得价值,如果有人比我更了解这一点,认为这应该起作用,我会尝试看看硬件是否损坏。