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
  • 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.

Children
No Data
Related