I2C in QuecOpen for EC21

Hi,

I would like to use I2C to read an external accelerometer. I’m using QuecOpen on EC21:

Quectel
EC21
Revision: EC21EFAR06A05M4G

SDK is: EC21EFAR06A05M4G_OCPU_20.001.20.001_SDK

I tried I2C example in ql-ext-sdk/example folder but if I check I2C_SCL and I2C_SDA using an oscilloscope but no signal is detected (note I added 4.7kohm resistor as pull-up to Vdd-ext).

Is I2C available for “generic purpose” or is it related only for CODEC interface?
Is it possible to remap it in the kernel?

Thanks for support!

Hi
The I2C interface can be used as a general interface. Check the software to ensure that the configuration is correct and can be used for external sensors.

Dear @Jouni.yang-Q,

I’m testing I2C using “example_i2c.c” reported in SDK example folder.

#include "ql_oe.h"


#define I2C_DEV         "/dev/i2c-2"	//i2c-2 on EC20xx, i2c-4 on AG35
#define I2C_SLAVE_ADDR  0x18	//codec 3104
#define WHO_AM_I        0x02
#define WHO_AM_I_VALUE  0x12


int main(int argc, char* argv[])  
{
    int iRet;

    /*
     * Open I2C device with read-write mode,
     * and write slave address.
     */
    int fd_i2c = Ql_I2C_Init(I2C_DEV);
    printf("< Ql_I2C_Init=%d >\n", fd_i2c);
    if (fd_i2c < 0)  
    {
        printf("< Fail to open i2c >\n");
        return -1;  
    }  

    /*
     * Write "who am i".
     */
    unsigned char wrtBuff[2] = {WHO_AM_I_VALUE, 0};
    iRet = Ql_I2C_Write(fd_i2c, I2C_SLAVE_ADDR, WHO_AM_I, wrtBuff, 1);
    printf("< write i2c value=0x%x, iRet=%d >\n", WHO_AM_I_VALUE, iRet);

    /*
     * Read the response for "who am i".
     */
    unsigned char rdBuff[2] = {0, 0};
    iRet = Ql_I2C_Read(fd_i2c, I2C_SLAVE_ADDR, WHO_AM_I, rdBuff, 1);
    printf("< read i2c iRet=%d, value=0x%x%x >\n", iRet, rdBuff[1], rdBuff[0]);//Little endian

    Ql_I2C_Deinit(fd_i2c);

Is “/dev/i2c-2” the correct one to use? I don’t see any CLK signal on oscilloscope on SCL pin. I expected to find some train of bits on oscilloscope.

Do you have another example I can test?

Thank you and regards.

Hello @Jouni.yang-Q,
Do you have any chance to send me a working example of I2C with EC21E and QuecOpen so I can test on my side?
Otherwise I have to think about to write i2c in bit-banging (which I would avoid…)

Thank you and regards

Hello @davdav,
did you solved?

Have a good day