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.

TMS320F28388D: I2C Clock is not generating and unable communicate with ADS1115 chip.

Part Number: TMS320F28388D
Other Parts Discussed in Thread: ADS1115

Tool/software:

Urgent help needed ,My I2C clock is not generating after I modified only application level of example code "i2c_ex4_eeprom_polling" to interface with ADS1115 chip.

#include "driverlib.h"
#include "device.h"

#include "i2cLib_FIFO_polling.h"

#define I2C_BASE            I2CA_BASE
#define ADS1115_I2C_ADDR    0x48

void I2C_Init(void);
void I2C_WriteRegister(uint8_t reg, uint16_t value);
uint16_t I2C_ReadRegister(uint8_t reg);
uint16_t ADS1115_ReadConversion(void);
void ADS1115_WriteConfig(uint16_t config);

void I2C_Init(void)
{
    I2C_disableModule(I2C_BASE);
    I2C_initMaster(I2C_BASE, DEVICE_SYSCLK_FREQ, 400000, I2C_DUTYCYCLE_50);
    I2C_setSlaveAddress(I2C_BASE, ADS1115_I2C_ADDR);
    I2C_setConfig(I2C_BASE, I2C_MASTER_SEND_MODE);
    I2C_enableModule(I2C_BASE);
}

void I2C_WriteRegister(uint8_t reg, uint16_t value)
{
    while(I2C_getStatus(I2C_BASE) & I2C_STS_BUS_BUSY);
    
    I2C_setConfig(I2C_BASE, I2C_MASTER_SEND_MODE);
    I2C_putData(I2C_BASE, reg);
    while(!(I2C_getStatus(I2C_BASE) & I2C_STS_TX_DATA_RDY));
    
    I2C_putData(I2C_BASE, (value >> 8) & 0xFF);
    while(!(I2C_getStatus(I2C_BASE) & I2C_STS_TX_DATA_RDY));
    
    I2C_putData(I2C_BASE, value & 0xFF);
    while(!(I2C_getStatus(I2C_BASE) & I2C_STS_TX_DATA_RDY));
    
    I2C_sendStopCondition(I2C_BASE);
}

uint16_t I2C_ReadRegister(uint8_t reg)
{
    uint16_t value = 0;
    
    while(I2C_getStatus(I2C_BASE) & I2C_STS_BUS_BUSY);
    
    I2C_setConfig(I2C_BASE, I2C_MASTER_SEND_MODE);
    I2C_putData(I2C_BASE, reg);
    while(!(I2C_getStatus(I2C_BASE) & I2C_STS_TX_DATA_RDY));
    I2C_sendStopCondition(I2C_BASE);
    
    I2C_setConfig(I2C_BASE, I2C_MASTER_RECEIVE_MODE);
    value = I2C_getData(I2C_BASE) << 8;
    I2C_sendAck(I2C_BASE);
    while(!(I2C_getStatus(I2C_BASE) & I2C_STS_RX_DATA_RDY));
    
    value |= I2C_getData(I2C_BASE);
    I2C_sendStopCondition(I2C_BASE);
    return value;
}

void ADS1115_WriteConfig(uint16_t config)
{
    I2C_WriteRegister(0x01, config);
}

uint16_t ADS1115_ReadConversion(void)
{
    return I2C_ReadRegister(0x00);
}

void main(void)
{
    Device_init();
    Device_initGPIO();
    I2C_Init();
    
    ADS1115_WriteConfig(0x8583); // Example Configuration
    
    while(1)
    {
        uint16_t adcValue = ADS1115_ReadConversion();
        DEVICE_DELAY_US(500000);
    }
}


I am providing my code in below ,I am quite new to C2000 platform , I need a guidance to know any configuration I did wrong or left ??

  • Hi, 

    Looking at your code snippet, seems like the GPIO pin configuration for I2C is missing.  

    Can you try adding these lines of code ?  

    //
    // Initialize GPIOs for use as SDA A and SCL A respectively
    //
    GPIO_setPinConfig(DEVICE_GPIO_CFG_SDAA);
    GPIO_setPadConfig(DEVICE_GPIO_PIN_SDAA, GPIO_PIN_TYPE_PULLUP);
    GPIO_setQualificationMode(DEVICE_GPIO_PIN_SDAA, GPIO_QUAL_ASYNC);

    GPIO_setPinConfig(DEVICE_GPIO_CFG_SCLA);
    GPIO_setPadConfig(DEVICE_GPIO_PIN_SCLA, GPIO_PIN_TYPE_PULLUP);
    GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCLA, GPIO_QUAL_ASYNC);

    Best Regards

    Siddharth

  • I already this section into my code .
    My slave device is also TI chip ads1115.
    It is giving ACK in I2C_Write_reg(0x48,0x01,0xC283) executing properly as ADS1115 giving ACK but in I2C_Read_reg(0x48,0x00)
    after writing 0x00 into I2CDXR which points to conversion register of ADS1115 I am getting NACK .
    What could be the reason ?? For the information I used TI pullup register calculation document and used exact 4.7kohm .

    Below I provided full code .

    #include "driverlib.h"
    #include "device.h"
    #include "stdio.h"
    
    #include "i2cLib_FIFO_polling.h"
    
    //
    // Globals
    //
    // ADS1115 Registers
    #define I2C_SLAVE_ADDR 0x48
    #define ADS1115_REG_CONVERSION 0x00
    #define ADS1115_REG_CONFIG 0x01
    #define ADS1115_REG_LO_THRESH 0x02
    #define ADS1115_REG_HI_THRESH 0x03
    
    // ADS1115 Configuration Bits (Example Configuration)
    #define ADS1115_CONFIG_OS_SINGLE 0x8000 // Single-shot conversion
    #define ADS1115_CONFIG_MUX_SINGLE_0 0x4000 // AIN0 and GND
    #define ADS1115_CONFIG_PGA_4_096V 0x0200 // +/- 4.096V range
    #define ADS1115_CONFIG_MODE_SINGLE 0x0100 // Single-shot mode
    #define ADS1115_CONFIG_DR_128SPS 0x0080 // 128 samples per second
    #define ADS1115_CONFIG_COMP_MODE_TRAD 0x0010 // Traditional comparator
    #define ADS1115_CONFIG_COMP_POL_LOW 0x0008 // Active low comparator
    #define ADS1115_CONFIG_COMP_LAT_NON 0x0004 // Non-latching comparator
    #define ADS1115_CONFIG_COMP_QUE_DIS 0x0003 // Disable comparator
    
    
    #define ADS1115_CONFIG (ADS1115_CONFIG_OS_SINGLE | ADS1115_CONFIG_PGA_4_096V | ADS1115_CONFIG_MODE_SINGLE | ADS1115_CONFIG_DR_128SPS | ADS1115_CONFIG_COMP_MODE_TRAD | ADS1115_CONFIG_COMP_POL_LOW | ADS1115_CONFIG_COMP_LAT_NON | ADS1115_CONFIG_COMP_QUE_DIS)
    
    void I2C_GPIO_init(void);
    void I2Cinit(void);
    void I2C_Write_reg(uint8_t devaddr, uint8_t reg, uint16_t val);
    uint16_t I2C_Read_reg(uint8_t devaddr, uint8_t reg);
    int16_t read_ads1115(void);
    int16_t adcvalue;
    
    
    void main(void)
    {
        Device_init();
        Device_initGPIO();
        I2C_GPIO_init();
        I2Cinit();
    
        I2C_Write_reg(I2C_SLAVE_ADDR, ADS1115_REG_CONFIG, ADS1115_CONFIG);
        DEVICE_DELAY_US(100000); // Wait for the conversion to complete 100ms
    
        while(1)
        {
            //if(getOSMode() == OS_READY)
            {
                adcvalue = read_ads1115();
                printf("ADC Value: %d\n", adcvalue);
                DEVICE_DELAY_US(100000);
            }
        }
    }
    
    
    
    void I2C_GPIO_init(void)
    {
        GPIO_setDirectionMode(DEVICE_GPIO_PIN_SDAB, GPIO_DIR_MODE_IN);
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SDAB, GPIO_PIN_TYPE_PULLUP);
        GPIO_setControllerCore(DEVICE_GPIO_PIN_SDAB, GPIO_CORE_CPU1);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SDAB, GPIO_QUAL_ASYNC);
    
        GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCLB, GPIO_DIR_MODE_IN);
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SCLB, GPIO_PIN_TYPE_PULLUP);
        GPIO_setControllerCore(DEVICE_GPIO_PIN_SCLB, GPIO_CORE_CPU1);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCLB, GPIO_QUAL_ASYNC);
    
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SDAB);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SCLB);
    }
    
    void I2Cinit(void)
    {
        I2C_disableModule(I2CB_BASE);
        I2C_initController(I2CB_BASE, DEVICE_SYSCLK_FREQ, 100000, I2C_DUTYCYCLE_33);
        I2C_setConfig(I2CB_BASE, I2C_CONTROLLER_SEND_MODE);
        I2C_setTargetAddress(I2CB_BASE, I2C_SLAVE_ADDR);
        I2C_disableLoopback(I2CB_BASE);
        I2C_setBitCount(I2CB_BASE, I2C_BITCOUNT_8);
        I2C_setAddressMode(I2CB_BASE, I2C_ADDR_MODE_7BITS);
        I2C_clearInterruptStatus(I2CB_BASE, I2C_INT_ARB_LOST | I2C_INT_NO_ACK);
        I2C_enableInterrupt(I2CB_BASE, I2C_INT_ADDR_TARGET | I2C_INT_ARB_LOST | I2C_INT_NO_ACK | I2C_INT_STOP_CONDITION);
        I2C_setEmulationMode(I2CB_BASE, I2C_EMULATION_FREE_RUN);
        I2C_enableModule(I2CB_BASE);
    }
    
    void I2C_Write_reg(uint16_t devaddr, uint8_t reg, uint16_t val)
    {
        while (I2C_STS_BUS_BUSY == 1);
        I2C_sendStartCondition(I2CB_BASE);
        I2C_setTargetAddress(I2CB_BASE, devaddr);
        DEVICE_DELAY_US(10);
        I2C_setDataCount(I2CB_BASE, 3);
    
        HWREGH(I2CB_BASE + I2C_O_DXR) = reg;
        HWREGH(I2CB_BASE + I2C_O_DXR) = (val >> 8) & 0xFF;
        HWREGH(I2CB_BASE + I2C_O_DXR) = val & 0xFF;
    
        //I2C_sendStartCondition(I2CB_BASE);
        
        I2C_setConfig(I2CB_BASE, I2C_CONTROLLER_SEND_MODE);
        //I2C_sendStartCondition(I2CB_BASE);
        I2C_sendStopCondition(I2CB_BASE);
        I2C_enableModule(I2CB_BASE);
        while (I2C_MDR_STP == 1);
    }
    
    uint16_t I2C_Read_reg(uint16_t devaddr, uint8_t reg)
    {
        uint16_t data;
        I2C_sendStartCondition(I2CB_BASE);
        I2C_setTargetAddress(I2CB_BASE, devaddr);
        I2C_setDataCount(I2CB_BASE, 1);
        I2C_putData(I2CB_BASE, reg);
        I2C_setConfig(I2CB_BASE, I2C_CONTROLLER_SEND_MODE);
        I2C_sendStopCondition(I2CB_BASE);
        DEVICE_DELAY_US(10);
        I2C_sendStartCondition(I2CB_BASE);
        while(I2C_isBusBusy(I2CB_BASE));
        I2C_setConfig(I2CB_BASE, I2C_CONTROLLER_RECEIVE_MODE);
        I2C_setDataCount(I2CB_BASE, 2);
        I2C_sendStartCondition(I2CB_BASE);
        data = I2C_getData(I2CB_BASE) << 8;
        data |= I2C_getData(I2CB_BASE);
        I2C_sendStopCondition(I2CB_BASE);
        printf("I2C Read Data: 0x%04X\n", data);
        return data;
    }
    
    int16_t read_ads1115(void)
    {
        int16_t result = (int16_t) I2C_Read_reg(I2C_SLAVE_ADDR, ADS1115_REG_CONVERSION);
        printf("ADS1115 Conversion Result: %d\n", result);
        return result;
    }