i2c - nrf9160dk

Good day

I am in the process of finalizing a project and am attempting to use the st25Dv04k nfc tag on the device but am having lots of trouble.  The board files only seem to have i2c2 defined but in testing with a slave device, I am not getting any sort of output from the defined SDA and SCL pins. The last posts on this subject are outdated and wanted to ask what could possibly be the issue?

Kind regards,

Hassan

prj 


CONFIG_I2C=y


main

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */



// #include <zephyr.h>
#include <stdio.h>
#include <string.h>
// #include <drivers/i2c.h>

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

#define I2C_SLAVE_ADDR 0xA6
#define I2C_DEV "I2C_2"


void main(void)
{
	struct device *i2c_dev  = DEVICE_DT_GET(DT_NODELABEL(i2c2));
	 
	struct i2c_msg msgs[1];
        uint8_t dst = 1,error;

        /* Send the address to read from */
        msgs[0].buf = &dst;
        msgs[0].len = 1U;
        msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

	printk("Starting i2c device...\n");

	// if (!device_is_ready(i2c_dev))
	// {}
    if (!device_is_ready(i2c_dev))
	{
		printk("UART device not found!");
		return;
	}
        i2c_configure(i2c_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));

        // error = i2c_transfer(i2c_dev, &msgs[0], 1, I2C_SLAVE_ADDR);
		k_sleep(K_MSEC(5000));
		for (int i=0;i<200;i++)
		{
        error = i2c_write(i2c_dev, &msgs[0], 1, i);
		if (error == 0) {
			printk("transfer complete");
			printk("%d", i );
		}

		else {
			printk("error %d \n", error);
			printk("%d", i );

		}
		}
}

Related