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 Children
Related