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

nrfx twis drivers on nrf9160 (Zephyr)

Hello,

I want to use I2C slave on nrf9160, but there is no I2C slave driver implementation.

So I read that instead of this, I can use nrfx twis drivers on nrf9160.

I followed this thread https://github.com/zephyrproject-rtos/zephyr/issues/21445 to use nrfx twis drivers on zephyr.

prj.conf

CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_TWIS=y
CONFIG_NRFX_TWIS0=y

nrf9160_pca10090ns.overlay

&i2c0 {
	compatible = "nordic,nrf-twis";
	status = "okay";
	sda-pin = < 19 >;
	scl-pin = < 18 >;
};

When I open the project with these prj.conf and overlay file, I am getting this error:

Loading solution twis_040820.emProject
Executing load commands
cmake -GNinja -DBOARD=nrf9160_pca10090ns -DBOARD_DIR=C:/ncs/zephyr/boards/arm/nrf9160_pca10090 -DZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb -DGNUARMEMB_TOOLCHAIN_PATH=C:/gnuarmemb -BC:/ncs/nrf/samples/jagruti_codes/twis_040820/build_nrf9160_pca10090ns -HC:/ncs/nrf/samples/jagruti_codes/twis_040820 -DDTC_OVERLAY_FILE=C:/ncs/nrf/samples/jagruti_codes/twis_040820/nrf9160_pca10090ns.overlay -DEXTRA_KCONFIG_TARGETS=menuconfig_ses -DEXTRA_KCONFIG_TARGET_COMMAND_FOR_menuconfig_ses=D:/nRF9160-DK/EmbeddedStudio_ARM_Nordic_v420a_win_x64/arm_segger_embedded_studio_v420a_win_x64_nordic/html/configure_nordic_project_menuconfig.py
-- Using application from 'C:/ncs/nrf/samples/jagruti_codes/twis_040820'
Zephyr version: 2.0.99
-- Selected BOARD nrf9160_pca10090ns
-- Found west: C:/Python37/Scripts/west.exe (found suitable version "0.6.2", minimum required is "0.6.0")
-- Cache files will be written to: C:\Users\b.carre\AppData\Local/.cache/zephyr
-- Loading C:/ncs/zephyr/boards/arm/nrf9160_pca10090/nrf9160_pca10090ns.dts as base
-- Overlaying C:/ncs/zephyr/dts/common/common.dts
-- Overlaying C:/ncs/nrf/samples/jagruti_codes/twis_040820/nrf9160_pca10090ns.overlay
device tree error: 'clock-frequency' appears in /soc/peripheral@40000000/i2c@8000 in nrf9160_pca10090ns.dts.pre.tmp, but is not declared in 'properties:' in C:/ncs/zephyr/dts/bindings\i2c\nordic,nrf-twis.yaml
CMake Error at C:/ncs/zephyr/cmake/dts.cmake:182 (message):
  new extractor failed with return code: 1
Call Stack (most recent call first):
  C:/ncs/zephyr/cmake/app/boilerplate.cmake:559 (include)
  CMakeLists.txt:2 (include)


-- Configuring incomplete, errors occurred!
Project load failed
Reported error: solution load command failed (1)

If I remove the compatible = "nordic,nrf-twis"; from overlay file, then there is no error but twis does not work.

Also while adding the IRQ handler, 

        IRQ_CONNECT(DT_NORDIC_NRF_I2C_I2C_2_IRQ_0, 
                            DT_NORDIC_NRF_I2C_I2C_2_IRQ_0_PRIORITY, 
                            nrfx_isr, nrfx_twis_2_irq_handler, 0);

I have these above options available.

But I should use:

IRQ_CONNECT(DT_NORDIC_NRF_TWIS_I2C_0_IRQ_0,
	    DT_NORDIC_NRF_TWIS_I2C_0_IRQ_0_PRIORITY,
	    nrfx_isr, nrfx_twis_0_irq_handler, 0);

But using this, I get the error.

How to solve this problem?

Parents Reply Children
  • nRF9160 supports up to 4x I2C compatible two-wire master/slave with EasyDMA

    Thanks Simon,

    Just to confirm - per quote above you are recommending using one of the unused serial slots as TWIS,  using nrfx, Not Zephyr driver, right?

    Browsing through various posts here on devzone and zephyr communities, what I understand about i2c-slave use on nRF9160: 
    a) Until ~3 weeks back Zephyr did Not have support for TWIS/ i2c slave. Though now there's "experimental" i2c slave support added to Zephyr - https://github.com/zephyrproject-rtos/zephyr/issues/27675 
    But nRF (including 9160) is explicitly excluded - because how EasyDMA is integral part of i2c operation -
    I think Zephyr driver needs byte-by-byte access to i2c registers.

    b) Per https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/i2c.h#L61 - it reads "The following #defines are used to configure the I2C slave device" - does that mean there's built in support for i2c_slave in current Zephyr for nRF9160? If not, what does this i2c slave device configuration is referring to/ how is it used?

    Will appreciate if you could please comment on what's my best bet for realizing i2c slave on nRF9160? Also is there any example code showing i2c slave in action (nrfx perhaps)? meant for nRF9160 or nRF52.
    Thanks.

    Best,
    SE

Related