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

Problem initializing I2C on Arduino Nano 33 BLE

I'm running into an issue in which I cannot initialized the I2C drivers on an Arduino Nano 33 BLE (nrf52840). The output from error logging is

Fullscreen
1
2
3
00> [00:00:00.500,122] <err> i2c_nrfx_twi: Error on I2C line occurred for message 0
00> [00:00:00.500,640] <err> HTS221: Failed to read chip ID.
00> [00:00:00.508,392] <err> i2c_nrfx_twi: Error 0x0BAD0001 occurred for message 0
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have this prj.conf file:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CONFIG_BOARD_ARDUINO_NANO_33_BLE=y
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_I2C_LOG_LEVEL_DBG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n
CONFIG_SPI=n
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_HTS221=y
CONFIG_HTS221_TRIGGER_NONE=y
CONFIG_LPS22HB=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have also modified the arduino_nano_33_ble.dts to enable mcu_boot and added the sensors into the &i2c1 device tree.

arduino_nano_33_ble.dts

Additionally, I changed zephyr/boards/arm/arduino_nano_33_ble/src/init_sensors.c such that initializing function is called at APPLICATION instead of PRE_KERNEL_1. Not sure why but initializing GPIO devices will cause the device to go fault at Pre_KERNEL_1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <init.h>
#include <arduino_nano_33_ble.h>
/*
* this method roughly follows the steps here:
* https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/6216632cc70271619ad43547c804dabb4afa4a00/variants/ARDUINO_NANO33BLE/variant.cpp#L136
*/
static int board_internal_sensors_init(const struct device *dev)
{
ARG_UNUSED(dev);
struct arduino_gpio_t gpios;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here's my main.c file.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>
#include <sys/util.h>
#include <stdio.h>
void main(void)
{
const struct device *dev = device_get_binding(DT_LABEL(DT_INST(0, st_hts221)));
const struct device *dev2 = device_get_binding(DT_LABEL(DT_INST(0, st_lps22hb_press)));
if (dev == NULL && dev2 == NULL) {
printf("Could not get devices\n");
return;
}
k_sleep(K_FOREVER);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Let me know if you want me to provide any other information about my setup. I'm currently flashing the board with a NRF52840dk with a JLink cable. I have been stuck on this problem for a few days now and I'm not sure what's the problem is.