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

AN36 question

this is quote from AN36> 4.2 Set up

The nRF51822 Evaluation Kit is needed for this application example. However, it is possible to modify the project to also work with the Development Kit. 4.2.1 Setting up the Evaluation board Since the nRF51822 Evaluation Kit has an onboard SEGGER chip, you can connect the Evaluation board through a USB cable and immediately start working on it. 4.2.2 Setting up the application A lot of boilerplate code is needed to get started creating an application and a service, so the first step is to copy code from the SDK:

  1. Go to Board\nrf6310\ble\ble_app_template folder.
  2. Copy this folder to Board\pca10001\ble\ and rename it to ble_app_lbs.
  3. Inside the Arm subfolder of ble_app_lbs change the name of the project files from ble_app_template to ble_app_lbs.

At the same time AN36 has folder code[u][/u] which includes ble_app_lbs.uvproj

Could someone please clarify.

The second question/clarification is where can I find parameters SD110 used on pca10005 and pca10004 for keil?

Thank you.

  • The ble_app_lbs folder that is included with the application note is a finished project, with all the code that is explained in the document. If copied to the folder explained in the document, it will work as described, but for learning, I'd strongly recommend you to work through the document step-by-step. When having done so, it might however be useful to compare your solution with the finished one.

    As for the differences between PCA10004/PCA10005 and the PCA10001, this is only the pins used for buttons and LEDs, meaning that it is sufficient to make sure those are correct depending on your board. The default ble_app_template uses the correct pins by default, so just take care not to replace them and use some other button and LED for LEDBUTTON_LED_PIN_NO and LEDBUTTON_BUTTON_PIN_NO.

  • I'm assuming than when initialization of (ble_gatts_attr_t)attr_char_value.init_len and (ble_gatts_attr_t)attr_char_value.max_len takes place sizeof of the attribute characteristic value should be used: i.e. if my initial value is string

    
    #define MAX_LEN 20
    char first[] = "hello world";
    char last[] = "good bye cruel world";
    
    

    During init

    
    attr_char_value.p_value = first;
    attr_char_value.init_len = strlen(first);
    attr_char_value.max_len = MAX_LEN;
    
    

    later

    
    attr_char_value.p_value = last;
    attr_char_value.init_len = strlen(last);
    
    

    Am I correct?

  • ble_bas.c

    
            if (
                (p_evt_write->handle == p_bas->battery_level_handles.cccd_handle)
                &&
                (p_evt_write->len == 2)
            )
    
    

    ble_lbs.c

    
            if (  
                  (p_evt_write->handle == p_lbs->led_char_handles.cccd_handle)
            && (p_evt_write->len == 1)
            && (p_lbs->led_write_handler != NULL)
            )
    
    

    My question is regarding p_evt_write->len. If this is new LED state then indeed it is defined as uint8_t and sizeof(uint8_t) is 1. What is being written to bas with length = 2?

    Or my assumptions are totally wrong and please explain what this length is representing.

    Thanks.

  • There is no use in modifying the attr_char_value after initialization, as it isn't used then. To change the value after init, you have to use sd_ble_gatts_value_set().

    However, the way of setting init_len and max_len seems reasonable.

  • The code snippet you post here from ble_lbs.c is not correct.

    When you receive a write, you can check the handle of the write to see which attribute was actually written. In the snippet from ble_bas.c, you can see that it waits for a write to the CCCD, and such writes should always be two bytes (CCCD is described in the Core Specification, Volume 3, Part G, section 3.3.3.3).

    However, the snippet you post from ble_lbs.c is intended to catch writes to the value of the LED characteristic (i.e. you should use value_handle, not cccd_handle), which will always be one byte.

    One additional comment: It's much easier for us to give you answers if you post unrelated questions as separate questions, instead of replies to an old question that have already been answered and resolved. It's easy that such replies are lost and forgotten, as happened with your reply above.

Related