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:

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);

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.

CONFIG_I2C=y
CONFIG_I2C_NRFX=y

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

Parents Reply
  • 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

Children
  • Hello,

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

    			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";
    			};

    		i2c1_default: i2c1_default {
    			phandle = < 0x4 >;
    			group1 {
    				psels = < 0xc0022 >, < 0xb0023 >;
    			};
    		};
    		i2c1_sleep: i2c1_sleep {
    			phandle = < 0x5 >;
    			group1 {
    				psels = < 0xc0022 >, < 0xb0023 >;
    				low-power-enable;
    			};
    		};

    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?

  • Additional note: Here is the current error log, and i2c_transfer still return -5.

  • Hi,

    Do you see anything on the lines for the I2C Scanner example?

    LandyWang said:
    instead of nrf5340 modul

    Is the nRF5340 module a custom board or our DK?
    Do you have an nRF5340DK?

    Regards,
    Sigurd Hellesvik

  • Hello,


    I see a 200mV signal on the SDA pin when power on, and then there is no signal.

    The nRF5340 module is custom board. I don't have an nRF5340DK but have nRF5340 audio DK.

    I have tried to use nRF5340 audio DK to test the audio sample that I added I2C and the I2C scanner sample, the logs are the same as on nRF5340 module.

    I compared the SCL signals of nRF5340 audio DK and nRF5340 module after programming nRF5340 audio sample that I added I2C. When I2C is idle, the nRF5340 audio DK is always at HI level, and the nRF5340 module is always at low level.

Related