I have tried to use I2C but it does't work out. nRF9160 doesn't start booting after executing "build and run" and pushing the reset button.
I open secure_boot project first and build and run. Then I open this project.
build and run is successful.
Any help?
OS: macOS Mojave
<prf.conf> CONFIG_TRUSTED_EXECUTION_NONSECURE=y CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_1_NRF_UARTE=y CONFIG_I2C=y CONFIG_I2C_NRFX=y CONFIG_I2C_0=y CONFIG_I2C_0_NRF_TWI=y CONFIG_I2C_INIT_PRIORITY=60
<nrf9160_pca10090.dts>
...
chosen {
zephyr,console = &uart0;
zephyr,debug = &uart1;
zephyr,i2c-accel = &i2c0;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
...
&i2c0 {
status = "ok";
sda-pin = <10>;
scl-pin = <11>;
clock-frequency = <100000>;
};
<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_0");
if (!i2c_accel) {
printk("error\r\n");
return -1;
} else {
i2c_configure(i2c_accel, I2C_SPEED_SET(I2C_SPEED_STANDARD));
return 0;
}
}
void main(void)
{
printk("Hello, World!\r\n");
init_accelerometer();
while (1) {
printk("loop head\r\n");
if (i2c_reg_read_byte(i2c_accel, I2C_ACCEL_READ_ADDR, 0x0F, WhoAmI) != 0) {
printk("Error on i2c_read()\n");
}
printk("WhoAmI = %u\r\n", WhoAmI);
printk("enter sleep\r\n");
k_sleep(1000);
}
}
<when pushing the reset button SW2> ... Secure Boot: SPU: set SRAM region 12 as Non-Secure Secure Boot: SPU: set SRAM region 13 as Non-Secure Secure Boot: SPU: set SRAM region 14 as Non-Secure Secure Boot: SPU: set SRAM region 15 as Non-Secure Secure Boot: SPU: set SRAM region 16 as Non-Secure Secure Boot: SPU: set SRAM region 17 as Non-Secure Secure Boot: SPU: set SRAM region 18 as Non-Secure Secure Boot: SPU: set SRAM region 19 as Non-Secure Secure Boot: SPU: set SRAM region 20 as Non-Secure Secure Boot: SPU: set SRAM region 21 as Non-Secure Secure Boot: SPU: set SRAM region 22 as Non-Secure Secure Boot: SPU: set SRAM region 23 as Non-Secure Secure Boot: SPU: set SRAM region 24 as Non-Secure Secure Boot: SPU: set SRAM region 25 as Non-Secure Secure Boot: SPU: set SRAM region 26 as Non-Secure Secure Boot: SPU: set SRAM region 27 as Non-Secure Secure Boot: SPU: set SRAM region 28 as Non-Secure Secure Boot: SPU: set SRAM region 29 as Non-Secure Secure Boot: SPU: set SRAM region 30 as Non-Secure Secure Boot: SPU: set SRAM region 31 as Non-Secure Secure Boot: configure peripherals Secure Boot: MSP_NS 200205d0 Secure Boot: prepare to jump to Non-Secure image // the device doesn't start booting