This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C issue with nrf52840 DK

Hello,

I am trying to learn bluetooth using nrf52840 USB dongle. I have created an application from sample beacon and i would like to use I2C to implement my own driver about a sensor.

I have succesfully configured and bind the node in the device tree.

According to same examples in net, i notice that they enable CONFIG_I2C_1=y

This option cannot be set in my application, due to there are missing depedencies I2C_ESP32. I cant understand why this depedency is needed.

I appreciate if you could help me a little bit about my issue.

bool initialize_sht21_driver(void)
{
    sht21_dev = DEVICE_DT_GET(DT_NODELABEL(i2c1));

    bool ret = device_is_ready(sht21_dev);
    if(ret)
    {
        printk("device is ready for use %d\n", ret);
    }
    else
    {
        printk("device is NOT ready for use %d\n", ret);
        return false;
    }


    sht21_dev = device_get_binding(DEVICE_DT_NAME(DT_NODELABEL(i2c1)));
    if(sht21_dev == NULL)
    {
        printk("device get binding returns NULL!!\n");
        return false;
    }

    ret = i2c_configure(sht21_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));
    if(ret != 0)
    {
        printk("i2c configuration issue!!\n");
    }
    return true;
}

############################################################################

void readTemperature(void)
{   
    struct i2c_msg msgs[1];
    msgs[0].buf = &dst;
    msgs[0].len = 1U;
    msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

    int error = i2c_transfer(sht21_dev, &msgs[0], 1, SHT21_ADDR);
    if(error == 0)
    {
        printk("i2c transfer ok!\n");
    }
    else 
    {
          printk("i2c transfer error!\n");
    }
    


}



Parents
  • Hello Thanos,

    According to same examples in net, i notice that they enable CONFIG_I2C_1=y

    Can you point me to that sample that you would like to add the sensor drivers to?

    This option cannot be set in my application, due to there are missing depedencies I2C_ESP32. I cant understand why this depedency is needed.

    Basically, there should be no need to set CONFIG_I2C_1, as the peripheral to be used will be enabled automatically from the devicetree when CONFIG_I2C is set.

    Regards,

    Markus

Reply
  • Hello Thanos,

    According to same examples in net, i notice that they enable CONFIG_I2C_1=y

    Can you point me to that sample that you would like to add the sensor drivers to?

    This option cannot be set in my application, due to there are missing depedencies I2C_ESP32. I cant understand why this depedency is needed.

    Basically, there should be no need to set CONFIG_I2C_1, as the peripheral to be used will be enabled automatically from the devicetree when CONFIG_I2C is set.

    Regards,

    Markus

Children
Related