Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

ESB payload

Hi,

 What is the role of the  NRF_ESB_CREATE_PAYLOAD()

static nrf_esb_payload_t        tx_payload = NRF_ESB_CREATE_PAYLOAD(1,0,0,0,0,0,0,0,0,0,0);

how it works

if i create payload on 8 byte only i can send 8 bytes !!

How to increase this to 252 bytes

in its macros it shows upto 63 bytes

#define NRF_ESB_CREATE_PAYLOAD(_pipe, ...)                                                  \
        {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}};         \
        STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 63)

/**@brief Macro to get the number of arguments in a call variadic macro call
 *
 * param[in]    ...     List of arguments
 *
 * @retval  Number of variadic arguments in the argument list
 */
#define NUM_VA_ARGS(...) NUM_VA_ARGS_IMPL(__VA_ARGS__, 63, 62, 61,  \
    60, 59, 58, 57, 56, 55, 54, 53, 52, 51,                         \
    50, 49, 48, 47, 46, 45, 44, 43, 42, 41,                         \
    40, 39, 38, 37, 36, 35, 34, 33, 32, 31,                         \
    30, 29, 28, 27, 26, 25, 24, 23, 22, 21,                         \
    20, 19, 18, 17, 16, 15, 14, 13, 12, 11,                         \
    10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

/**@brief Implementation details for NUM_VAR_ARGS */
#define NUM_VA_ARGS_LESS_1_IMPL(                       \
    _ignored,                                          \
    _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10,       \
    _11, _12, _13, _14, _15, _16, _17, _18, _19, _20,  \
    _21, _22, _23, _24, _25, _26, _27, _28, _29, _30,  \
    _31, _32, _33, _34, _35, _36, _37, _38, _39, _40,  \
    _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,  \
    _51, _52, _53, _54, _55, _56, _57, _58, _59, _60,  \
    _61, _62, N, ...) N

/**@brief Macro to get the number of arguments in a call variadic macro call.
 * First argument is not counted.
 *
 * param[in]    ...     List of arguments
 *
 * @retval  Number of variadic arguments in the argument list
 */
#define NUM_VA_ARGS_LESS_1(...) NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 63, 62, 61,  \
    60, 59, 58, 57, 56, 55, 54, 53, 52, 51,                         \
    50, 49, 48, 47, 46, 45, 44, 43, 42, 41,                         \
    40, 39, 38, 37, 36, 35, 34, 33, 32, 31,                         \
    30, 29, 28, 27, 26, 25, 24, 23, 22, 21,                         \
    20, 19, 18, 17, 16, 15, 14, 13, 12, 11,                         \
    10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ~)

  • The ESB protocol can support up to 252bytes payload, this is done by setting NRF_ESB_MAX_PAYLOAD_LENGTH 252 in nrf_esb.h. You can find in update_rf_payload_format_esb_dpl() that when max payload length is set higher than 32byte, then the length field in the payload is increased from 6 to 8bit (thereby supporting longer than 32byte payload, up to 252bytes in this case).

    I can find from the description of NRF_ESB_CREATE_PAYLOAD() in nrf_esb.h.

    /** @brief Macro to create an initializer for a TX data packet.
     *
     * @details This macro generates an initializer. Using the initializer is more efficient
     *          than setting the individual parameters dynamically.
     *
     * @param[in]   _pipe   The pipe to use for the data packet.
     * @param[in]   ...     Comma separated list of character data to put in the TX buffer.
     *                      Supported values consist of 1 to 63 characters.
     *
     * @return  Initializer that sets up the pipe, length, and byte array for content of the TX data.
     */
    #define NRF_ESB_CREATE_PAYLOAD(_pipe, ...)                                                  \
            {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}};         \
            STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 63)

    I can find this macro was only made for 6bit field length, since it check if the payload is shorter than 63bytes. If you set max payload to 252bytes I suggest to change it to the following:

    /** @brief Macro to create an initializer for a TX data packet.
     *
     * @details This macro generates an initializer. Using the initializer is more efficient
     *          than setting the individual parameters dynamically.
     *
     * @param[in]   _pipe   The pipe to use for the data packet.
     * @param[in]   ...     Comma separated list of character data to put in the TX buffer.
     *                      Supported values consist of 1 to 63 characters.
     *
     * @return  Initializer that sets up the pipe, length, and byte array for content of the TX data.
     */
    #define NRF_ESB_CREATE_PAYLOAD(_pipe, ...)                                                  \
            {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}};         \
            STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 252)

    Then for instance you can use NRF_ESB_MAX_PAYLOAD_LENGTH(0, your_payload_up_to_252bytes);

    Kenneth

  • Hi,

    I have changed these things

    in nrf_esb.h

    // Hardcoded parameters - change if necessary
    #ifndef NRF_ESB_MAX_PAYLOAD_LENGTH
    #define     NRF_ESB_MAX_PAYLOAD_LENGTH          252                  //!< The maximum size of the payload. Valid values are 1 to 252.
    #endif
    

    in nrf_esb.c

    static void update_rf_payload_format_esb_dpl(uint32_t payload_length)
    {
    #if (NRF_ESB_MAX_PAYLOAD_LENGTH <= 32)
        // Using 6 bits for length
        NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) |
                           (6 << RADIO_PCNF0_LFLEN_Pos) |
                           (3 << RADIO_PCNF0_S1LEN_Pos) ;
    #else
        // Using 8 bits for length
        NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) |
                           (8 << RADIO_PCNF0_LFLEN_Pos) |
                           (3 << RADIO_PCNF0_S1LEN_Pos) ;
    #endif
        NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled    << RADIO_PCNF1_WHITEEN_Pos) |
                           (RADIO_PCNF1_ENDIAN_Big          << RADIO_PCNF1_ENDIAN_Pos)  |
                           ((m_esb_addr.addr_length - 1)    << RADIO_PCNF1_BALEN_Pos)   |
                           (0                               << RADIO_PCNF1_STATLEN_Pos) |
                           (NRF_ESB_MAX_PAYLOAD_LENGTH      << RADIO_PCNF1_MAXLEN_Pos);
    }

    #define NRF_ESB_CREATE_PAYLOAD(_pipe, ...)                                                  \
            {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}};         \
            STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 252)
    
    

    static nrf_esb_payload_t        tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0,0, \
                                                                           0,0,0,0,0,0,0,0,0,0,0);

    for this i got error

    Building ‘esb_ptx_pca10056’ from solution ‘esb_ptx_pca10056’ in configuration ‘Release’
      Compiling ‘main.c’
        sdk_common.h
        main.c
        static assertion failed: "unspecified message"
        in definition of macro '_SELECT_ASSERT_FUNC'
        in expansion of macro 'STATIC_ASSERT_SIMPLE'
        in expansion of macro 'STATIC_ASSERT'
        in expansion of macro 'NRF_ESB_CREATE_PAYLOAD'
    Build failed

  • Looks like the NUM_VA_ARGS() and NUM_VA_ARGS_IMPL() only support up to 63bytes.

    In that case I suggest you don't use the macro, but do it manually:

        static nrf_esb_payload_t tx_payload;
    
        tx_payload.pipe = 0;
        tx_payload.length = NRF_ESB_MAX_PAYLOAD_LENGTH;
        for(uint8_t i; i<NRF_ESB_MAX_PAYLOAD_LENGTH; i++)
          tx_payload.data[i] = i;

    The above will just create a payload with 0, 1, 2, 3, ... 251.

Related