I followed this: devzone.nordicsemi.com/.../164005
You add an .overlay file in the application folder (where the applications CMakeLists.txt is located). And when using the nrf91DK you call this file "nrf9160_pca10090.overlay".
In this file you add what pins you would like to use for the peripherals.
ex. to activate TWI
- add this to the .overlay file
&i2c2 {
status = "ok";
sda-pin = <11>;
scl-pin = <12>;
clock-frequency = <I2C_BITRATE_STANDARD>;
};
# Enable I2C
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_I2C_2=y
CONFIG_I2C_2_NRF_TWIM=y
Then I wrote a simple main.c
#include <zephyr.h>
#include <bsd.h>
#include <nrf_socket.h>
#include <net/socket.h>
#include <stdio.h>
#include <i2c.h>
struct device * i2c_dev;
struct device * gpio_dev;
{
i2c_dev = device_get_binding(I2C_DEV_NAME);
if (i2c_dev == NULL)
{
printk("Could not get %s device\n", I2C_DEV_NAME);
return;
}
else
{
printk("Well, we got the binding for %s device\n", I2C_DEV_NAME);
}
}
static bool verify_id(void)
{
u8_t val = 0;
int err = i2c_reg_read_byte(i2c_dev, 0x60, 0x10, &val);
if (err)
{
printk("i2c_reg_read_byte err = %d, value = %d\n", err, val);
}
else
{
printk("i2c read (0x%x from this address 0x%x)\n", val, REG_HARDWARE_ID);
}
return true;
}
{
printk("Staring I2C application\n");
i2c_init();
verify_id();
while (1)
{
verify_id();
printk("Sleepy\n");
k_sleep(500);
}
return 0;
}