nrf5340 audio I2C error -5

Hello,

I want to add an audio amplifier controlled by I2C on nrf5340 module.

After referring to some I2C samples, I added the following code to my nrf5340 audio sample:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
static const struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c1));
typedef unsigned char BYTE;
struct i2c_msg msg;
memset(&msg, 0, sizeof(msg));
BYTE write_bytes[2];
write_bytes[0]=0x1A;
write_bytes[1]=0x50;
/* Setup I2C message */
msg.buf = write_bytes;
msg.len = 2;
msg.flags = I2C_MSG_WRITE | I2C_MSG_STOP;
log_ret = i2c_transfer(i2c_dev, &msg, 1, I2C_SLAVE_ADDRESS);
printk("ret = %d\n",log_ret);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I write some data via I2C. However,it occurs error:

And i2c_transfer return -5, it seems like an I/O error.

I use default I2C pin in nrf5340 audio sample, and I disabled other devices that use I2C, such as the ina231, in the nrf5340 audio sample, so this error is not caused by sharing I2C.

Here is the config I added to my prj.conf.

Fullscreen
1
2
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Is there anything else that needs to be modified when I use I2C ?

  • Hi,

    Can you test this unofficial Simple I2C scanner sample?

    Is it able to scan your sensor?

    Regards,
    Sigurd Hellesvik

  • Hello,

    Thank you for your reply.

    I tested with the I2C scanner sample and received the same results.

    Here is the log:

    Is it a hardware issue?

  • Hi,

    From nrfx_errors.h we can see that the error code is NRFX_ERROR_INTERNAL.

    LandyWang said:
    Is it a hardware issue?

    I am guessing it is either a devicetree error or a hardware issue.

    Can you post the i2c1 definition from build/zephyr/zephyr.dts?

    To check for a hardware error, connect an oscilloscope or logic analyzer to the I2C lines to look for a signal here.

    How have you connected the I2C sensor to the nRF5340?
    And to clarify, which Development Kit are you using?

    Regards,
    Sigurd Hellesvik

  • Hello,

    Here is the i2c1 part in my build/zephyr/zephyr.dts.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    i2c1: i2c@9000 {
    compatible = "nordic,nrf-twim";
    #address-cells = < 0x1 >;
    #size-cells = < 0x0 >;
    reg = < 0x9000 0x1000 >;
    clock-frequency = < 0x186a0 >;
    interrupts = < 0x9 0x1 >;
    status = "okay";
    pinctrl-0 = < &i2c1_default >;
    pinctrl-1 = < &i2c1_sleep >;
    pinctrl-names = "default", "sleep";
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    i2c1_default: i2c1_default {
    phandle = < 0x4 >;
    group1 {
    psels = < 0xc0022 >, < 0xb0023 >;
    };
    };
    i2c1_sleep: i2c1_sleep {
    phandle = < 0x5 >;
    group1 {
    psels = < 0xc0022 >, < 0xb0023 >;
    low-power-enable;
    };
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I connected the I2C sensor to the nRF5340 only with SDA/SCL pins, and the I2C sensor has independent power supply.

    I will use an oscilloscope to check hardware issue next week. Before that, I want to confirm whether there is a problem with the software.

    The nRF Connect SDK version I used is v2.2.0.

  • Hello,

    I use an oscilloscope to check the signal of the SDA pin, it seems that there is no data output.

    I can't find where the code is wrong. I compared other I2C samples, the writing method is the same, and the I2C pins I use are also the default pins.

    In addition, I tried to test with nrf5340 audio dk instead of nrf5340 module, but got the same error.

    What situation does this I2C error -5 usually appear?

1 2 3