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

connect to the nRF52840-DK with the STM32F103 development board

Hi, recently I want to establish a connection between two development boards (STM32F103 + nRF52840-DK), that the STM32f103 board can create the data and send it to the nRF52840-DK, the openwsn has been ported to the nRF52840-DK. I want to combine development boards and Component wireless sensor networks. But I find that the nRF52840-DK has only one usart port pin(reference datasheet), If there has the other UARTport I don't find, please correct me. So I want to use other communication protocols (like I2C and SPI, etc). But I am not familiar with 52840 programming, I hope I can provide some help.

  • I want to use the UART1 to transmit the data from my board, and I can not find any useful instructions on how to configure UART1. below is another people code that configuring the UART0 by directly accessing the register(I can not confirm if right). I also want to configure uart1 using the register.

    void uart_init(){

    NRF_P0->OUTSET = 1 << UART_TX_PIN;//Set UART pin number bits in GPIO port

    // tx pin configured as output
    NRF_P0->PIN_CNF[UART_TX_PIN] = \
    ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
    | ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
    | ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
    | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
    | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);

    // rx pin configured as input // 执行的就该函数是 nrf_gpio_cfg_input()-->nrf_gpio_cfg
    NRF_P0->PIN_CNF[UART_RX_PIN] = \
    ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
    | ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
    | ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
    | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
    | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);

    // configure uart

    NRF_UART0->BAUDRATE = (uint32_t)(UART_BAUDRATE_115200);
    NRF_UART0->CONFIG =
    (uint32_t)(UART_CONFIG_PARITY << UART_CONFIG_PARITY_POS)
    | (uint32_t)(UART_CONFIG_HWFC << UART_CONFIG_HWFC_POS);
    NRF_UART0->PSEL.RXD = (uint32_t)UART_RX_PIN;
    NRF_UART0->PSEL.TXD = (uint32_t)UART_TX_PIN;

    // enable UART rx done ready and tx done ready interrupts

    NRF_UART0->INTENSET =
    (uint32_t)(1<<UART_INTEN_RXDRDY_POS)
    | (uint32_t)(1<<UART_INTEN_TXDRDY_POS);

    // set priority and enable interrupt in NVIC
    NVIC_SetPriority(UARTE0_UART0_IRQn, NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY);

    NVIC->ISER[((uint32_t)UARTE0_UART0_IRQn)>>5] =
    ((uint32_t)1) << ( ((uint32_t)UARTE0_UART0_IRQn) & 0x1f);

    // enable uart
    NRF_UART0->ENABLE = (uint32_t)UART_ENABLE_ENABLE_Enabled;

    // start to tx and rx
    NRF_UART0->TASKS_STARTTX = (uint32_t)1;
    NRF_UART0->TASKS_STARTRX = (uint32_t)1;}

  • Hello again,

    kyh-ly said:
    I want to use the UART1 to transmit the data from my board, and I can not find any useful instructions on how to configure UART1.

    Have you seen the UART peripheral hardware example from the SDK
    It demonstrates how you could use the UART peripheral, and how to configure which UART instance you will be using in the sdk_config file.

    kyh-ly said:
    below is another people code that configuring the UART0 by directly accessing the register(I can not confirm if right)

    Where did you find this code? I would recommend that you make use of the supplied UART drivers, or app uart library, rather than working with the peripheral's registers directly. Especially if you are not comfortable with working at the register level.

    Best regards,
    Karl

  • Thank you, The first thing I must to do is familiar with the SDK and the hardware.

  • Hello again,

    Yes, this is an excellent idea. The nRF5 SDK's examples demonstrates a lot of the features available to the nRF device series, and how you may go about using them. I recommend starting with a non-BLE example ( such as the UART example I linked in my previous reply ), to get familiar with the peripheral, and then moving on to one of the examples that include BLE ( Such as the ble_app_uart examples ).

    Please do not hesitate to open a new ticket on the forum if you should encounter any issues or questions!

    Best regards,
    Karl

  • I want to know how to specify the specific configuration of the UART1. I always configure the UART0 and the UART1 doesn't work.Which files should I modify.

    void uart_init(){

    const app_uart_comm_params_t comm_params =
    {
    SER_APP_RX_PIN,SER_APP_TX_PIN,
    SER_APP_RTS_PIN,SER_APP_CTS_PIN,
    /*RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,*/
    UART_HWFC,
    false,
    #if defined (UART_PRESENT)
    NRF_UART_BAUDRATE_115200
    #else
    NRF_UARTE_BAUDRATE_115200
    #endif
    };

    APP_UART_FIFO_INIT(&comm_params,
    UART_RX_BUF_SIZE,
    UART_TX_BUF_SIZE,
    uart_error_handle,
    APP_IRQ_PRIORITY_LOWEST,
    err_code);

    APP_ERROR_CHECK(err_code);

    }

Related