nrf9160dk i2c2

Good day everyone

I am attempting to to use my  x-nucleo-nfc04a1  tag reader device on my nrf9160dk.  I cant seem to find a sample that could help me.  At the moment I am simply just trying to confirm the connection.  I am trying to use the i2c2 line to establish the connection and my understanding is that this code should work.  Please assist as to why it isnt.  The device is connected correctly to the nrf9160dk .  Below is my very simple code.  I do not have an overlay file as I believe it shoudn't be necessary

main.c


/*
 * Copyright (c) 2015 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <errno.h>
#include <zephyr/zephyr.h>
#include <zephyr/sys/printk.h>
#include <zephyr/device.h>
// #include <zephyr/drivers/i2c.h>
#include <drivers/i2c.h>





#define MY_I2C "I2C_2"

void main(void)
{
	
const struct device * i2c2_dev;

// Get the device binding to the I2C peripheral
i2c2_dev = device_get_binding(MY_I2C);
if (i2c2_dev == NULL) {
	printk("Unable to bind %s!\n", MY_I2C);
	return;
}

	
}
   
   
prj   
   
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y

CONFIG_I2C=y
.

I am using pins n 30 and 31 as the SDA and SCL connection.  Please assist urgently.

  • Hello

    I believe the "device_get_binding" is on its way to get deprecated, and I'm not sure where you have this "I2C_2" label from?

    Anyway, I believe the current way of doing this would look like this:

    i2c2_dev = DEVICE_DT_GET(DT_NODELABEL(i2c2));

    If this doesn't work as expected, please share any error logs or describe in what way your code doesn't work.

    Best regards,

    Einar

Related