AnsweredAssumed Answered

MKL03Z: I2C module: Cannot send a "start" without sending a "stop" prior

Question asked by Gaurav Banyal on Jun 29, 2017
Latest reply on Jul 3, 2017 by Gaurav Banyal

I have a question on using the I2Cmodule. I am writing the driver for an I2C EEPROM and I need to do the following for performing a read operation on the EEPROM. Note that after sending the address of the byte I want to read, I have to send a start again (without a preceeding stop). This doesn’t seem to be possible in I2C module.

 

How I am trying to achieve this is by doing two transactions on the I2C bus. First to write the “Byte addr” bytes. This I am ending without a STOP bit. The next to read the data byte.

==============

bool eeprom_read_byte(uint16_t address, uint8_t * data){

 

    //Get the I2C instance handle

    I2C_Type * i2c_handle = NULL;

                        i2c_handle = i2c_shared_init();

   

    i2c_master_transfer_t masterXfer = {

        .slaveAddress   = EEPROM_I2C_SLAVE_ADDR_7BIT,

                                                .direction      = kI2C_Write,

                                                .subaddress     = (uint32_t) address,

                                                .subaddressSize = 2,

                                                .data           = NULL,

                                                .dataSize       = 0,

                                                .flags          = kI2C_TransferNoStopFlag

                        };

   

    status_t status = I2C_MasterTransferBlocking( i2c_handle, &masterXfer );

   

                        if( kStatus_Success != status ){

                                                PRINTF(("%s[%d], %s() - I2C_MasterTransferBlocking failed: %d\r\n", __FILE__, __LINE__, __func__, status));

                                                return FAILED;

                        }

   

    masterXfer.slaveAddress   = EEPROM_I2C_SLAVE_ADDR_7BIT;

    masterXfer.direction      = kI2C_Read;

    masterXfer.subaddress     = (uint32_t) address;

    masterXfer.subaddressSize = 0;

    masterXfer.data           = data;

    masterXfer.dataSize       = 1;

    masterXfer.flags          = kI2C_TransferDefaultFlag;

 

    status = I2C_MasterTransferBlocking( i2c_handle, &masterXfer ); è This always returns error kStatus_I2C_Busy

 

    if (kStatus_Success != status){

                                                PRINTF(("%s[%d], %s() - I2C_MasterTransferBlocking failed: %d\r\n", __FILE__, __LINE__, __func__, status));

        return FAILED;

                        }

   

                        return SUCCESSFUL;

}

==============

The “kStatus_I2C_Busy” is returned from the following code inside I2C_MasterStart() function and below is the explanation of this from the reference manual.

 

    /* Return an error if the bus is already in use. */

    if (statusFlags & kI2C_BusBusyFlag)

    {

        result = kStatus_I2C_Busy;

    }

 

 

Please suggest me how I can achieve the I2C communication needed to perform a read operation on this I2C EEPROM.

Outcomes