I2C Problem

Hello to all,
I’m having problem reading data from a PCA9534A via I2C. I’m actually using a Q2686 with R72 firmware and I always get a ADL_RET_ERR_PARAM, I can’t understand where is the error. The same circuit works fine with Q2686 - 6.63 FW .
Here the testing code:

u8 string[50];
s32 ret;
u32 addr_len;
u8 i2c_read_buffer[5];
s32 i2c_handle;
adl_busI2CSettings_t i2c_config;
adl_busAccess_t i2c_access_config;

i2c_config.AddrLength   = ADL_BUS_I2C_ADDR_7_BITS;
i2c_config.ChipAddress   = (0x7a>>1);
i2c_config.Clk_Speed   = ADL_BUS_I2C_CLK_STD;
i2c_config.MasterMode   = ADL_BUS_I2C_MASTER_MODE;

i2c_handle = adl_busSubscribe(ADL_BUS_I2C, 1, &i2c_config);

wm_sprintf(string,"[I2C_HANDLE] %d \r\n",i2c_handle);
adl_atSendResponse ( ADL_AT_UNS, string);

addr_len = ADL_BUS_I2C_CAP_ADD_SIZE_8;

ret = adl_busIOCtl(i2c_handle, ADL_BUS_CMD_SET_ADD_SIZE, &addr_len);
wm_sprintf(string,"[I2C_ADDR_LEN] SET %d \r\n",ret);
adl_atSendResponse ( ADL_AT_UNS, string);

i2c_access_config.Address = 0;
i2c_access_config.Opcode  = 0;

ret = adl_busRead(i2c_handle, &i2c_access_config, 1,i2c_read_buffer);

wm_sprintf(string,"[I2C_READ] %x ERROR %d\r\n",i2c_read_buffer[0],ret);
adl_atSendResponse ( ADL_AT_UNS, string);

adl_busUnsubscribe(i2c_handle );

Thank you for you help,

Raffaele

Have you checked carefully that the APIs are identical in R7.2 and R6.63 :question:

Wavecom have made some significant changes to the API over time - and attempting to use the wrong form would certainly account for a Parametererror…

Yeah, I know that I2C library is completely different from R72 to 6.63. I’ve posted the code for R72, it’s very similar to the example in ADL manual, and with I have no problem reading a I2C EEPROM 24Cxx. Just I’m wondering why so simple code doesn’t work.

wich command gives you ADL_RET_ERR_PARAM?

Just because code appears “simple” is no reason to beleive that it can’t contain errors!

adl_busRead

Thank you for the wise sentence, but if you know how to find the error I’ll appreciate

As you know that it’s adl_busRead that’s giving the error, look carefully at the parameters that you are supplying and carefully check that they match the specification of adl_busRead

you might want to change

ret = adl_busRead(i2c_handle, &i2c_access_config, 1,i2c_read_buffer);

to

ret = adl_busRead(i2c_handle, &i2c_access_config, 1,&i2c_read_buffer);

That shouldn’t matter, as i2c_read_buffer is declared as an array - so using just its name does give the address of its 1st element…?

Are you sure adl_busSubscribe is giving you a valid handle?

I knew that, and it doesn’t work too.

  1. adl_busSubscribe gives a valid handle (it’s 403449256)
  2. adl_busIOCtl returns OK

I’ve tried also to set a delay time between every function but the same result.

Aren’t you required to give an address when you read from I2C?

i2c_access_config.Address = 0;
i2c_access_config.Opcode  = 0;

-edit-
never mind my reply
sorry, i’m confusing some things here

[quote=“Madouc”]
Aren’t you required to give an address when you read from I2C?

i2c_access_config.Address = 0;
i2c_access_config.Opcode  = 0;

I want to read IC register 0

hmm… this is my (working) code.

I’m using FW. 7.4a (OS 6.31)

/**	@brief Led driver I2C configuration settings.
 */
const adl_busI2CSettings_t LedI2CConfig[2] = {
	{
		0x12, ///< Chip address to write to (not shifted)
		ADL_BUS_I2C_CLK_FAST, ///< Chip uses the I2C fast clock speed
		ADL_BUS_I2C_ADDR_7_BITS, ///< 7 bits address length
	},
	{
		0x62, ///< Chip address to write to (not shifted)
		ADL_BUS_I2C_CLK_FAST, ///< Chip uses the I2C fast clock speed
		ADL_BUS_I2C_ADDR_7_BITS, ///< 7 bits address length
	}
};

/// opcode/address used on current Bus access.
adl_busAccess_t i2cLedBusAcces = {0, 0};

/// I2C address size
u32 AddSize=8;

/// BUS Handles
s32 LedI2CHandle[2]={0,0};


    s32 handle = adl_busSubscribe ( ADL_BUS_ID_I2C, 1, (void *)&MyI2CConfig );

    adl_busAccess_t i2cBusAcces = {0, 0};

    adl_busIOCtl ( handle, ADL_BUS_CMD_SET_ADD_SIZE, &AddSize );
    adl_busIOCtl ( handle, ADL_BUS_CMD_SET_ASYNC_MODE, NULL );
    s32 dataSize = 8;
    adl_busIOCtl ( handle, ADL_BUS_CMD_SET_DATA_SIZE, &dataSize );
    i2cBusAcces.Address = (0x11)<<24;
    u8 dat[14];
    ret = adl_busRead ( handle, &i2cBusAcces, 1, &dat);

Thank you very much, it works just adding

adl_busIOCtl ( handle, ADL_BUS_CMD_SET_ASYNC_MODE, NULL );

regarding address size,

/// I2C address size
u32 AddSize=8;

are you sure you don’t need to use a value indicated in adl_busI2CCap_e?
for 8 bit address is ADL_BUS_I2C_CAP_ADD_SIZE_8 and not simply 8.

Anyway i’ll do some experiments and I’ll let you know, thank again for the advise.

ok, i hadn’t noticed that…
tried to change it, but now my I2C isn’t working anymore…

the examples given by Wavecom are also using numbers:

u32 drv_I2C_E2P_M24CXX_Init ( void )
{
    u32 length = 16;
    
    adl_busI2CSettings_t I2CSettings =
    {
        0x50,                   // ChipAddress
        ADL_BUS_I2C_CLK_STD     // Clk_Speed 
    };

(475 - 483 of extstorage_iic.c)

the chip used in the example has a 16-bits address.