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.

CCS/TM4C1294NCPDT: I2C HDC2080

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: HDC2080

Tool/software: Code Composer Studio

I'm having trouble reading and writing data on the HDC2080 sensor, when I add some writing commands in a row, the data is not written to the sensor...
And if I try to read data sequentially, all readings return the same value, sometimes the same value as the first read, and sometimes the second read value.

What could this be?

void initI2C9(uint32_t clock1)
{

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C9);

    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C9);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    ROM_GPIOPinConfigure(GPIO_PA0_I2C9SCL);
    ROM_GPIOPinConfigure(GPIO_PA1_I2C9SDA);

    ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_0);
    ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_1);

    ROM_I2CMasterInitExpClk(I2C9_BASE, clock1, true);

    HWREG(I2C9_BASE + I2C_O_FIFOCTL) = 80008000;
}

uint8_t buf;

uint8_t readI2C9(uint16_t device_address, uint16_t device_register)
{
    ROM_I2CMasterSlaveAddrSet(I2C9_BASE, device_address, false);

    ROM_I2CMasterDataPut(I2C9_BASE, device_register);

    ROM_I2CMasterControl(I2C9_BASE, I2C_MASTER_CMD_SINGLE_SEND);

    while(ROM_I2CMasterBusy(I2C9_BASE));

    ROM_I2CMasterSlaveAddrSet(I2C9_BASE, device_address, true);

    ROM_I2CMasterControl(I2C9_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

    while(ROM_I2CMasterBusy(I2C9_BASE));

    buf= ROM_I2CMasterDataGet(I2C9_BASE);

	return(buf);
}

void writeI2C9(uint16_t device_address, uint16_t device_register, uint8_t device_data)
{
    ROM_I2CMasterSlaveAddrSet(I2C9_BASE, device_address, false);

    ROM_I2CMasterDataPut(I2C9_BASE, device_register);

    ROM_I2CMasterControl(I2C9_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    while(ROM_I2CMasterBusy(I2C9_BASE));

    ROM_I2CMasterSlaveAddrSet(I2C9_BASE, device_address, true);

    ROM_I2CMasterDataPut(I2C9_BASE, device_data);

    ROM_I2CMasterControl(I2C9_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);

    while(ROM_I2CMasterBusy(I2C9_BASE));
}



  • Hi,

     In your writeI2C9() function I'm not too sure why you need the second ROM_I2CMasterDataPut(I2C9_BASE, device_data). I'm not familiar with the HDC2080 but in the datasheet it says that after you change to the slave address for the read the master should be just waiting for the data. However, you are trying to write another data after you change the slave address for read.

    Can you try something in the writeI2C9 like below and see if makes a difference?
    // lines before are not shown 

           while(!I2CMasterBusy(I2C9_BASE)) // Add this line

        while(ROM_I2CMasterBusy(I2C9_BASE));
    
        ROM_I2CMasterSlaveAddrSet(I2C9_BASE, device_address, true); //
    
        ROM_I2CMasterControl(I2C9_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

           while(!I2CMasterBusy(I2C9_BASE)) // Add this line

        while(ROM_I2CMasterBusy(I2C9_BASE));
        buf= ROM_I2CMasterDataGet(I2C9_BASE);

  • Resending the code sequence again.

    while(!I2CMasterBusy(I2C9_BASE)) // Add this line
    while(ROM_I2CMasterBusy(I2C9_BASE));
    ROM_I2CMasterSlaveAddrSet(I2C9_BASE, device_address, true); //
    ROM_I2CMasterControl(I2C9_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
    while(!I2CMasterBusy(I2C9_BASE)) // Add this line
    while(ROM_I2CMasterBusy(I2C9_BASE));
    buf= ROM_I2CMasterDataGet(I2C9_BASE);
  • It worked, but with only a small change in the code, before each

    while(ROM_I2CMasterBusy (I2C9_BASE));

    I added what you suggested:

     while(!ROM_I2CMasterBusy(I2C9_BASE));

    The code is working perfectly now!

    Thank you