This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Trouble: TWI(I2C) stops at the function of i2c_reg_read_byte On nRF9160 DK. Why?

I'm trying to have nRF9160 DK communicate with an external accelerometer. 

nRF9160 stop working at the function of i2c_reg_read_byte in the code below.

Does anybody give any advice?

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<main.c>
#include <nrf9160.h>
#include <zephyr.h>
#include <misc/printk.h>
#include <i2c.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define I2C_ACCEL_WRITE_ADDR 0x32
#define I2C_ACCEL_READ_ADDR 0x33
struct device *i2c_accel;
uint8_t WhoAmI = 0u;
uint8_t init_accelerometer(){
i2c_accel = device_get_binding("I2C_2");
if (!i2c_accel) {
printk("error\r\n");
return -1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<prj.conf>
CONFIG_TRUSTED_EXECUTION_SECURE=y
# needed to get the NRF_UARTE2 define
CONFIG_UART_2_NRF_UARTE=y
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_INIT_PRIORITY=60
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<overlay file>
/* needed to get the NRF_UARTE2 defined */
&uart2 {
current-speed = <1000000>;
status = "ok";
tx-pin = <18>;
rx-pin = <17>;
rts-pin = <19>;
cts-pin = <21>;
};
&i2c2 {
status = "ok";
sda-pin = <10>;
scl-pin = <11>;
clock-frequency = <100000>;
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

UPDATE:

Fullscreen
1
2
3
4
5
<printk>
***** Booting Zephyr OS v1.13.99-ncs2 *****
Hello, World!
loop head
// stack here
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX