I2C1 port not responding

I have a nRF9160DK board running tagoio_http_post. I am trying to use the I2C1 port. I have attached the overlay file I use to set I2C1 to P0.30 and P0.31. I have also attached prj.conf file.

I have a simple I2C test setup that I have added below. The result when I run the program is an error (-5) as shown below. can you tell me what I am doing wrong and how I get the I2C1 command to work? I am sure it is something simple I am missing. I appreciate any help you can give.

******************************

#if 1
/* start I2C test */
#include <zephyr/drivers/i2c.h>

#if DT_NODE_HAS_STATUS(DT_ALIAS(i2c1), okay)
#define I2C_DEV_NODE    DT_ALIAS(i2c1)
/#else
#error "Please set the correct I2C device"
#endif

const struct device *const i2c_dev = DEVICE_DT_GET(I2C_DEV_NODE);
uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_STANDARD) | I2C_MODE_CONTROLLER;
//uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_FAST) | I2C_MODE_CONTROLLER;

/* end I2C test */
#endif
#if 1
/* start I2C test */

    printf("*** I2C Init ***\r\n");

    if (!device_is_ready(i2c_dev))
    {
        myPrintfE("I2C device is not ready\r\n");
    }
    else
        myPrintfS("I2C device is ready\r\n");

    /* 1. Verify i2c_configure() */
    if (i2c_configure(i2c_dev, i2c_cfg))
    {
        myPrintfE("I2C config failed\n");
    }
    else
        myPrintfS("I2C config passed\n");

#if 1
    unsigned char datas[6];
    while(1)
    {
        /* 4. verify i2c_read() */
        datas[0] = 0xFC;
        i2c_write(i2c_dev, datas, 1, 0x40);

        int ret = i2c_read(i2c_dev, datas, 2, 0x40);
        printf("I2C 0x%02X 0x%02X %d\r\n",datas[0],datas[1],ret);
        k_sleep(K_MSEC(1000));
    }
#endif

/* end I2C test */
#endif
************************ results when run ********************

*** I2C Init ***
I2CI2C device is ready
I2C config passed
I2C 0xFC 0x00 -5
[00:00:00.754,333] <err> i2c_nrfx_twim: Error on I2C line occurred for message 0
[00:00:01.254,516] <err> i2c_nrfx_twim: Error on I2C line occurred for message 0

0743.prj.conf2818.data_logger_agriculture.overlay

Parents Reply Children
Related