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.

TM4C123GH6PM: EDU-MKII Reading from OPT3001 with i2c.

Part Number: TM4C123GH6PM
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!

  • Hello Jared

    The code seems to be correct. Can you make the following change and then see if the return value is correct.

    Replace

    while(I2CMasterBusy(I2C1_BASE));

    with

    SysCtlDelay(100)
    while(I2CMasterBusy(I2C1_BASE));

    Also it would be advisable to connect a scope probe and see if the OPT3001 is indeed sending the 2 bytes of the Manufacturer ID correctly.