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.

RTOS/TM4C123GH6PM: TI-RTOS: TM4C I2C API to access an external 24C256 EEPROM

Part Number: TM4C123GH6PM

Tool/software: TI-RTOS

Hi,

I'm using I2C APIs of TI-RTOS (v2.16) to access an external EEPROM 24C256 on my Tiva-C launchpad . The program executes normally in CCS V6.1.2, but the data read from EEPROM is not equal to the data written. The data read from 24C256 are all '0'. I'm pretty sure that the I2C0 configuration and I install 2.2K ohm resistor on the PB2 and PB3 pins.

  I wonder how "I2C_transfer()" knows if the EEPROM is 1-byte memory address or 2-byte address since I can't find any parameters to specify this. I don't have the chance to try 1-byte address EEPROM like 24C02 and besides my project needs to use 24C256.

I list both the write and read routines below ( They are copied from TI-RTOS example with slight modifications. Any help will be appreciated and thanks in advance.

Eric

    void    Task_Write_24C256( uint8_t *data_ptr, uint16_t transfer_cnt )   // declared as a task in CCS
    {
        unsigned int        i = 0;
        I2C_Handle          handle;
        I2C_Params          i2cparams;
        I2C_Transaction     i2c;
        
        I2C_Params_init(&i2cparams);
        i2cparams.bitRate = I2C_400kHz;
        
        //i2cparams.transferMode = I2C_MODE_BLOCKING;
        //i2cparams.transferCallbackFxn = NULL;
        
        handle = I2C_open( Board_I2C0, &i2cparams );
        
        if (handle == NULL)
            System_abort("I2C was not opened");            
            
        i2c.slaveAddress = I2C_SLAVE_ADDR_FRAM;
        
        i2c.readCount = 0;                // clear read-parameters when not read access
        i2c.readBuf = NULL;
        
        
        i2c.writeBuf = data_ptr;            // set valid write-parameters for write access    
        i2c.writeCount = transfer_cnt;
        
        if (!I2C_transfer(handle, &i2c))
        {
            
            System_printf("Bad I2C transfer !");
            System_flush();
    
            System_abort("Bad I2C transfer !");
        }                
        
        
        I2C_close( handle);
    
    }
    
    void    Task_Read_24C256( uint8_t *data_ptr, uint16_t transfer_cnt )  //  declared as a task in CCS
    {
        unsigned int        i = 0;
        I2C_Handle          handle;
        I2C_Params          i2cparams;
        I2C_Transaction     i2c;
        
        I2C_Params_init(&i2cparams);
        
        i2cparams.bitRate = I2C_400kHz;
        
        //i2cparams.transferMode = I2C_MODE_BLOCKING;
        //i2cparams.transferCallbackFxn = NULL;
        
        
        handle = I2C_open( Board_I2C0, &i2cparams );

        if (handle == NULL)
            System_abort("I2C was not opened");
                

        i2c.slaveAddress = I2C_SLAVE_ADDR_FRAM;
        
        i2c.readCount = transfer_cnt;        // set valid read-parameters for read access
        i2c.readBuf = data_ptr ;
        
        i2c.writeBuf = NULL;            // clear write-parameters when not write access
        i2c.writeCount = 0;
        
        if (!I2C_transfer(handle, &i2c))
        {
            
            System_printf("Bad I2C transfer !");
            System_flush();
    
            System_abort("Bad I2C transfer !");
        }                
        
        I2C_close( handle);
    }
   

  • Eric,

    Eric Chen49 said:
     i2c.writeBuf = NULL;            // clear write-parameters when not write access
            i2c.writeCount = 0;

    In I2C, I think, the master has to issue a command to the slave device to perform an action. In this case to read back the bytes of some length from an address. Since your writebuf is not set up with a command for slave device, I am wondering if that is causing an issue.

    Eric Chen49 said:
    handle = I2C_open( Board_I2C0, &i2cparams );

    I think it would be sufficient to open I2C driver once and use the same handle for both of your operations.

    Vikram