Greetings,
We are developing a new application based on NCS 2.1.0. Right now we are using the nRF52840DK and we are performing some tests on the basic examples/samples and functionality such as BLE, Thread communication, and finally I2C.
We tried communicating with an I2C sensor (LSM6DSO Evaluation kit) that is operating correctly when run with our verified drivers on nRF5 SDK (17.1.0) and we get back a correct response ( we are reading the device ID and data correctly ) which has been verified so our hardware connection is correct (as seen in the capture below ).
When we run the simple example code found in nRF Connect SDK Fundamentals course, Lesson 6 Exercise 1 we get back error from the i2c function
Below is our code:
prj.conf
# STEP 2 - Enable the I2C driver CONFIG_I2C=y # STEP 4.2 - Enable floating point format specifiers CONFIG_CBPRINTF_FP_SUPPORT=y
nrf52840dk_nrf52840.overlay (I2C slave address of our sensor is 0x6a)
// To get started, press Ctrl+Space to bring up the completion menu and view the available nodes. // You can also use the buttons in the sidebar to perform actions on nodes. // Actions currently available include: // * Enabling / disabling the node // * Adding the bus to a bus // * Removing the node // * Connecting ADC channels // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html // You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html &i2c0 { mysensor: mysensor@6a{ compatible = "i2c-device"; reg = < 0x6a >; label = "MYSENSOR"; }; };
main.c
/* * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 * * Note: Tested on nRF52833 DK */ #include <zephyr.h> #include <device.h> #include <devicetree.h> /* STEP 3 - Include the header file of the I2C API */ #include <drivers/i2c.h> /* STEP 4.1 - Include the header file of printk() */ #include <sys/printk.h> /* 1000 msec = 1 sec */ #define SLEEP_TIME_MS 1000 /* STEP 8 - Define the I2C slave device address and the addresses of relevant registers */ #define STTS751_TEMP_HIGH_REG 0x00 #define STTS751_TEMP_LOW_REG 0x02 #define STTS751_CONFIG_REG 0x03 /* STEP 6 - Get the node identifier of the sensor */ #define I2C0_NODE DT_NODELABEL(mysensor) void main(void) { int ret; /* STEP 7 - Retrieve the API-specific device structure and make sure that the device is ready to use */ static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE); if (!device_is_ready(dev_i2c.bus)) { printk("I2C bus %s is not ready!\n\r",dev_i2c.bus->name); return; } /* STEP 9 - Setup the sensor by writing the value 0x8C to the Configuration register */ uint8_t config_tx = 0x0F; ret = i2c_write_dt(&dev_i2c, &config_tx, sizeof(config_tx)); if(ret != 0){ printk("Failed to write to I2C device address %x at Reg. %x \n\r", dev_i2c.addr,config_tx); } uint8_t config_rx[1]; ret = i2c_read_dt(&dev_i2c, config_rx, sizeof(config_rx)); printk("Read from I2C device address %x at Reg. %x the value %x\n\r",dev_i2c.addr,config_tx, config_rx[0]); while (1) { /* STEP 10 - Read the temperature from the sensor */ /* STEP 11 - Convert the two bytes to a 12-bits */ } }
The serial output is:
Failed to write to I2C device address 6a at Reg. f Read from I2C device address 6a at Reg. f the value 0
And the scope from the logic analyzer shows that only the second command (i2c_read_dt) was executed:
What is the issue here? We have tried running the same code in different projects with various i2c commands( i2c_write_read , i2c_burst_read etc. ) but got the same results.
Are we missing something? It seems that we followed the exercise steps exactly and our hardware connection has been verified to work correctly.
What could be the issue?
Thank you for your time and I'm looking forward to hearing from you!
Best regards,
Stavros Filippas