I'm trying to get basic i2c code working on my Nordic nFR9160DK board. I'm new to the platform and have been doing a lot of reading and searching through examples. Through these efforts, I've managed to scrape together some code that I'm hoping is close to working. I'm using nRF Connect SDK v1.7.1 and VS Code. The port I'm working with is i2c2 on pins 30 and 31 of the development kit. When I build the code I get the following error:
'DT_N_ALIAS_i2c_2_P_label' undeclared (first use in this function)
Here's my code:
CMakeLists.txt
cmake_minimum_required(VERSION 3.13.1)
set(DTC_OVERLAY_FILE
${CMAKE_CURRENT_SOURCE_DIR}/nrf9160_pca10090ns.overlay
)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(i2c_scanner)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
nrf9160_pca10090ns.overlay
&i2c2 {
status = "okay";
compatible = "nordic,nrf-twim";
sda-pin = < 30 >;
scl-pin = < 31 >;
clock-frequency = <I2C_BITRATE_STANDARD>;
};
prj.conf
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_SERIAL=y
#CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
#CONFIG_I2C_2=y
#CONFIG_I2C_2_NRF_TWIM=y
CONFIG_NEWLIB_LIBC=y
#CONFIG_LOG=y
#CONFIG_I2C_LOG_LEVEL_DBG=y
#CONFIG_LOG_BACKEND_UART=y
#CONFIG_I2C_INIT_PRIORITY=60
main.c
#include <zephyr.h>
#include <device.h> //added this
#include <devicetree.h> //added this
#include <sys/printk.h>
#include <drivers/i2c.h>
#include <drivers/gpio.h>
#define I2C_ACCEL_WRITE_ADDR 0x32
#define I2C_ACCEL_READ_ADDR 0x75
struct device * i2c_accel;
uint8_t WhoAmI = 0u;
#define I2C_DEV DT_LABEL(DT_ALIAS(i2c_2))
void main(void)
{
const struct device *i2c_dev;
k_sleep(K_MSEC(500));
i2c_dev = device_get_binding(I2C_DEV);
if (!i2c_dev) {
printk("I2C: Device driver not found.\n");
return;
}
uint8_t error = 0u;
i2c_configure(i2c_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));
//printk("Value of NRF_TWIM3_NS->PSEL.SCL: %ld \n",NRF_TWIM3_NS->PSEL.SCL);
//printk("Value of NRF_TWIM3_NS->PSEL.SDA: %ld \n",NRF_TWIM3_NS->PSEL.SDA);
//printk("Value of NRF_TWIM3_NS->FREQUENCY: %ld \n",NRF_TWIM3_NS->FREQUENCY);
//printk("26738688 -> 100k\n");
for (uint8_t i = 4; i <= 0x77; i++) {
struct i2c_msg msgs[1];
uint8_t dst = 1;
/* Send the address to read from */
msgs[0].buf = &dst;
msgs[0].len = 1U;
msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;
error = i2c_transfer(i2c_dev, &msgs[0], 1, i);
if (error == 0) {
printk("0x%2x FOUND\n", i);
}
else {
//printk("error %d \n", error);
}
}
}
Again, the error I'm getting is "'DT_N_ALIAS_i2c_2_P_label' undeclared". I understand from my reading that this is a generated macro, but beyond that my knowledge is a bit hazy. The error seems to originate at the following line in main.c