Other Parts Discussed in Thread: OPT3001
I am currently using a Tiva C series development board with the EDU-MKII booster pack that contains on on board OPT3001 chip. The interface to this chip is i2c. I am having a difficulty reading from the manufacturer ID register on the OPT3001. I can correctly read the MSB, but the LSB is always all 1's. Here is the code I am using:
int16_t lsb;
int16_t msb;
int16_t three;
//-------------------------------------- SEND ----------------------------------------------------------
//specify that we are writing (a register address) to the
//slave device
I2CMasterSlaveAddrSet(I2C1_BASE, slaveAdr, false);
//specify register to be read
I2CMasterDataPut(I2C1_BASE, MANUFACTUREID_REG);
//send control byte and register address byte to slave device
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_SEND);
// Wait until the slave has received and acknowledged the data.
while(I2CMasterBusy(I2C1_BASE));
//-------------------------------------- RECEIVE ----------------------------------------------------------
//specify that we are reading (a register address) to the
//slave device
I2CMasterSlaveAddrSet(I2C1_BASE, slaveAdr, true);
//send control byte and read from the register we
//specified
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C1_BASE));
msb = (I2CMasterDataGet(I2C1_BASE) & 0xFF);
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); //Receive
while(I2CMasterBusy(I2C1_BASE));
lsb = (I2CMasterDataGet(I2C1_BASE) & 0xFF );
result = (msb << 8) | lsb;
In debugging I get msb = 0000000001010100b (correct)
and lsb = 0000000011111111b (incorrect)
Does anyone see anything wrong with the above code? To my understanding it should work correctly.. Thanks!