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

Configuration UARTE with nrf52805 for ESB - Part 2


My previous ticket is closed. I would need, but still help with the configuration of the pins. I report my last post.

Hello,
I did some tests with the oscilloscope directly connected to pins 21 and 18 of the nrf52805.
The transmission on pin 18 by the Stm8l works perfectly. The problem I encounter now is that nrf52805 I have the pull up instruction on this pin

 nrf_gpio_cfg_input(PIN_RXD,GPIO_PIN_CNF_PULL_Pullup);

but nothing happens when oscilloscopes.
It could be that I get the pin definition wrong initially

 #define UARTE_BASE           0x40002000
  #define PORTA_UARTE          ((NRF_UARTE_Type *) UARTE_BASE )
  #define PIN_TXD            21
  #define PIN_RXD            18


or the pull up configuration of pin 18, set as input and pin 21 as output?

 nrf_gpio_cfg_input(PIN_RXD,GPIO_PIN_CNF_PULL_Pullup);
     nrf_gpio_cfg_output(PIN_TXD);
Parents
  • Hi,

    Sorry for the delay. I took a look at the code.

    Since you have APP_UART_FLOW_CONTROL_ENABLED, you also want to set the CTS and RTS pin:

            .cts_pin_no   = CTS_PIN;
            .rts_pin_no   = RTS_PIN;

    Instead of calling nrf_esb_write_payload() all the time in the main()-while-loop, you can instead call it in the UART handler.

    Something like this:

    /**
     * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    
    #include "nrf.h"
    #include "nrf_esb.h"
    #include "nrf_error.h"
    #include "nrf_esb_error_codes.h"
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "app_uart.h"
    
    #include "nrf_uarte.h"
    
    #include "boards.h" //rimane per i led 
    
    #include "nrf_delay.h"
    #include "app_util.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    #include "sdk_common.h"
    
    
             
      #define UARTE_BASE           0x40002000
      #define PORTA_UARTE          ((NRF_UARTE_Type *) UARTE_BASE )
      #define PORTA_TXD            6
      #define PORTA_RXD            8
      #define PORTA_RTS            5
      #define PORTA_CTS            7
      
      #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
      #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    
    static nrf_esb_payload_t        tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00);
    static nrf_esb_payload_t        rx_payload;
    
    /**@brief   Function for handling app_uart events.
     *
     * @details This function will receive a single character from the app_uart module and append it to
     *          a string. The string will be be sent over BLE when the last character received was a
     *          'new line' '\n' (hex 0x0A) or if the string has reached the maximum data length.
     */
    /**@snippet [Handling the data received over UART] */
    void uart_event_handle(app_uart_evt_t * p_event)
    {
       
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&tx_payload.data[index]));
                index++;
    
                if ((tx_payload.data[index - 1] == '\n') ||
                    (tx_payload.data[index - 1] == '\r') ||
                    (index >= 20))// valore massimo da poter invare su uart suggerimento preso dall'esempio del ble_uart
                {
                    if (index > 1)
                    {
                        nrf_esb_write_payload(&tx_payload);
                        NRF_LOG_DEBUG("Ready to send data over ESB");
                        NRF_LOG_HEXDUMP_DEBUG(tx_payload.data, index);
                    }
    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
        }
    }
    /**@snippet [Handling the data received over UART] */
    
    
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = PORTA_RXD,
            .tx_pin_no    = PORTA_TXD,
            .cts_pin_no   = PORTA_CTS,
            .rts_pin_no   = PORTA_RTS,
            .flow_control = APP_UART_FLOW_CONTROL_ENABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UARTE_BAUDRATE_2400
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
        APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    
    void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
    
        switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
             //   NRF_LOG_DEBUG("TX SUCCESS EVENT");
                break;
            case NRF_ESB_EVENT_TX_FAILED:
             //   NRF_LOG_DEBUG("TX FAILED EVENT");
                (void) nrf_esb_flush_tx();
                (void) nrf_esb_start_tx();
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
            //    NRF_LOG_DEBUG("RX RECEIVED EVENT");
                while (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                {
                    if (rx_payload.length > 0)
                    {
                //        NRF_LOG_DEBUG("RX RECEIVED PAYLOAD");
                    }
                }
                break;
        }
    }
    
    
    void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    void gpio_init( void )
    {
        nrf_gpio_range_cfg_output(8, 15);
        bsp_board_init(BSP_INIT_LEDS);
    }
    
    
    uint32_t esb_init( void )
    {
        uint32_t err_code;
        uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
    
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.retransmit_delay         = 600;
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PTX;
        nrf_esb_config.selective_auto_ack       = false;
    
        err_code = nrf_esb_init(&nrf_esb_config);
    
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_0(base_addr_0);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_1(base_addr_1);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_prefixes(addr_prefix, NRF_ESB_PIPE_COUNT);
        VERIFY_SUCCESS(err_code);
    
        return err_code;
    }
    
    
    int main(void)
    {
         ret_code_t err_code;
         
         gpio_init();
         uart_init();
         
         
         err_code = NRF_LOG_INIT(NULL);
         APP_ERROR_CHECK(err_code);
         
         NRF_LOG_DEFAULT_BACKENDS_INIT();
    
         clocks_start();
    
         err_code = esb_init();
         APP_ERROR_CHECK(err_code);
        
         NRF_LOG_INFO("Enhanced ShockBurst Transmitter Example started.");
        
         while (true)
         {
            __SEV();
            __WFE();
            __WFE();
        
         }
       
    }
    

    PS: I also set NRFX_PRS_BOX_2_ENABLED to 1 in sdk_config.h to in order to get it to compile.

    Here is the SES project I used to run it "emulated" on a nRF52832-DK:

    esb_ptx_modified.zip

    If you run it on a real nRF52805, you want to use these startup-files instead:

      , and remove the DEVELOP_IN_NRF52832 preprocessor define.

    BR,

    Sigurd

Reply
  • Hi,

    Sorry for the delay. I took a look at the code.

    Since you have APP_UART_FLOW_CONTROL_ENABLED, you also want to set the CTS and RTS pin:

            .cts_pin_no   = CTS_PIN;
            .rts_pin_no   = RTS_PIN;

    Instead of calling nrf_esb_write_payload() all the time in the main()-while-loop, you can instead call it in the UART handler.

    Something like this:

    /**
     * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    
    #include "nrf.h"
    #include "nrf_esb.h"
    #include "nrf_error.h"
    #include "nrf_esb_error_codes.h"
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "app_uart.h"
    
    #include "nrf_uarte.h"
    
    #include "boards.h" //rimane per i led 
    
    #include "nrf_delay.h"
    #include "app_util.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    #include "sdk_common.h"
    
    
             
      #define UARTE_BASE           0x40002000
      #define PORTA_UARTE          ((NRF_UARTE_Type *) UARTE_BASE )
      #define PORTA_TXD            6
      #define PORTA_RXD            8
      #define PORTA_RTS            5
      #define PORTA_CTS            7
      
      #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
      #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    
    static nrf_esb_payload_t        tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00);
    static nrf_esb_payload_t        rx_payload;
    
    /**@brief   Function for handling app_uart events.
     *
     * @details This function will receive a single character from the app_uart module and append it to
     *          a string. The string will be be sent over BLE when the last character received was a
     *          'new line' '\n' (hex 0x0A) or if the string has reached the maximum data length.
     */
    /**@snippet [Handling the data received over UART] */
    void uart_event_handle(app_uart_evt_t * p_event)
    {
       
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&tx_payload.data[index]));
                index++;
    
                if ((tx_payload.data[index - 1] == '\n') ||
                    (tx_payload.data[index - 1] == '\r') ||
                    (index >= 20))// valore massimo da poter invare su uart suggerimento preso dall'esempio del ble_uart
                {
                    if (index > 1)
                    {
                        nrf_esb_write_payload(&tx_payload);
                        NRF_LOG_DEBUG("Ready to send data over ESB");
                        NRF_LOG_HEXDUMP_DEBUG(tx_payload.data, index);
                    }
    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
        }
    }
    /**@snippet [Handling the data received over UART] */
    
    
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = PORTA_RXD,
            .tx_pin_no    = PORTA_TXD,
            .cts_pin_no   = PORTA_CTS,
            .rts_pin_no   = PORTA_RTS,
            .flow_control = APP_UART_FLOW_CONTROL_ENABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UARTE_BAUDRATE_2400
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
        APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    
    void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
    
        switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
             //   NRF_LOG_DEBUG("TX SUCCESS EVENT");
                break;
            case NRF_ESB_EVENT_TX_FAILED:
             //   NRF_LOG_DEBUG("TX FAILED EVENT");
                (void) nrf_esb_flush_tx();
                (void) nrf_esb_start_tx();
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
            //    NRF_LOG_DEBUG("RX RECEIVED EVENT");
                while (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                {
                    if (rx_payload.length > 0)
                    {
                //        NRF_LOG_DEBUG("RX RECEIVED PAYLOAD");
                    }
                }
                break;
        }
    }
    
    
    void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    void gpio_init( void )
    {
        nrf_gpio_range_cfg_output(8, 15);
        bsp_board_init(BSP_INIT_LEDS);
    }
    
    
    uint32_t esb_init( void )
    {
        uint32_t err_code;
        uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
    
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.retransmit_delay         = 600;
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PTX;
        nrf_esb_config.selective_auto_ack       = false;
    
        err_code = nrf_esb_init(&nrf_esb_config);
    
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_0(base_addr_0);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_1(base_addr_1);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_prefixes(addr_prefix, NRF_ESB_PIPE_COUNT);
        VERIFY_SUCCESS(err_code);
    
        return err_code;
    }
    
    
    int main(void)
    {
         ret_code_t err_code;
         
         gpio_init();
         uart_init();
         
         
         err_code = NRF_LOG_INIT(NULL);
         APP_ERROR_CHECK(err_code);
         
         NRF_LOG_DEFAULT_BACKENDS_INIT();
    
         clocks_start();
    
         err_code = esb_init();
         APP_ERROR_CHECK(err_code);
        
         NRF_LOG_INFO("Enhanced ShockBurst Transmitter Example started.");
        
         while (true)
         {
            __SEV();
            __WFE();
            __WFE();
        
         }
       
    }
    

    PS: I also set NRFX_PRS_BOX_2_ENABLED to 1 in sdk_config.h to in order to get it to compile.

    Here is the SES project I used to run it "emulated" on a nRF52832-DK:

    esb_ptx_modified.zip

    If you run it on a real nRF52805, you want to use these startup-files instead:

      , and remove the DEVELOP_IN_NRF52832 preprocessor define.

    BR,

    Sigurd

Children
No Data
Related