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

How can i use 4 Serial peripheral interface on nrf9160

I created a project on nrf9160, which connects many peripherals, including SPI,I2C,UART. According to the specification, nrf9160 can use up to 4 sets of serial peripherals at the same time because of address sharing. However, the actual situation is that when I use SPI2,SPI3,I2C1 at the same time, I can't get the binding of SPI2, and when I use SPI2,SPI3,UART1 at the same time, they are all ok, why?

Parents Reply Children
  • In fact, i just turned on different switches in the prj.conf file and didn't change to the address, It has failed to get the binding, and it has not reached the location where the address is set, like this:

    void SPI_Flash_Init(void)
    {
    	spi_flash = device_get_binding(FLASH_DEVICE);
    	if (!spi_flash) 
    	{
    		printk("Could not get %s device\n", FLASH_DEVICE);
    		return;
    	}
    
    	spi_cfg.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
    	spi_cfg.frequency = 4000000;
    	spi_cfg.slave = 0;
    }

    My prj.conf file:

    #
    # Copyright (c) 2019 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    
    # General config
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_ASSERT=y
    CONFIG_REBOOT=y
    CONFIG_GPIO=y
    CONFIG_LOG=y
    CONFIG_LOG_IMMEDIATE=y
    
    # AT_CMD
    CONFIG_AT_CMD=y
    CONFIG_AT_NOTIF=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    
    # Modem info
    CONFIG_MODEM_INFO=y
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    CONFIG_BSD_LIBRARY_TRACE_ENABLED=n
    
    # Library for buttons and LEDs
    CONFIG_DK_LIBRARY=y
    CONFIG_DK_LIBRARY_INVERT_LEDS=n
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    CONFIG_MAIN_STACK_SIZE=8192
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_HW_STACK_PROTECTION=y
    
    # MCUBOOT
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_IMG_MANAGER=y
    CONFIG_MCUBOOT_IMG_MANAGER=y
    
    # SPI
    CONFIG_SPI=y
    CONFIG_SPI_NRFX=y
    CONFIG_SPI_2=y
    CONFIG_SPI_2_NRF_SPIM=y
    CONFIG_SPI_3=y
    CONFIG_SPI_3_NRF_SPIM=y
    
    # I2C
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_I2C_1=y
    CONFIG_I2C_1_NRF_TWIM=y
    CONFIG_I2C_INIT_PRIORITY=60
    
    # Flash
    CONFIG_FLASH=y
    CONFIG_IMG_ERASE_PROGRESSIVELY=y
    
    # NVS
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_NVS=y
    CONFIG_LOG=y
    CONFIG_NVS_LOG_LEVEL_DBG=y
    CONFIG_REBOOT=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    
    # UART
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_LINE_CTRL=y
    #CONFIG_UART_0_NRF_UARTE=y
    #CONFIG_UART_0_NRF_FLOW_CONTROL=n
    CONFIG_UART_1_NRF_UARTE=y
    CONFIG_UART_1_NRF_FLOW_CONTROL=n
    
    # Use smaller buffers for net_buf as CANBUS packets are quite small.
    CONFIG_NET_BUF_DATA_SIZE=64
    CONFIG_NET_BUF_USER_DATA_SIZE=1

  • Which NCS version are you using?

    You do not need to enable the:

    CONFIG_I2C_NRFX=y

    CONFIG_SPI_NRFX=y

    Since you are not using the nrfxlib directly.

    So you can remove those lines. (you also have some configs repeated several time.(e.g. config_flash))

    In this prj.conf file I see that you have enabled SPI2,SPI3,I2C1,UARTso that won't work per my statement.

  • I'm using ncs v1.2.0, when I was testing, I did not turn on I2C1 and UART1 at the same time. As I said, when I turn on SPI2\SPI3\UART1, they are all ok.When I turn on SPI2\SPI3\I2C1, I find that my SPI2 does not work.it can't get the binding of SPI2.

  • I did find I2C_1 and I2C_2 enabled in the autoconf.h file, but in fact I only enabled I2C_1, not I2C_2. Who started I2C_2 automatically?

  • Hi duxinglang,

    Maybe you have earlier configured some board files?

    anyway, try to set 

    CONFIG_I2C_2=n
    CONFIG_I2C_2_NRF_TWIM=n

Related