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

NUS with Scanner

I can scan beacons with Scanner. and can use NUS (ble_periperall\ble_app_uart ) to get connect with device.

My goal is to combine both application Have NUS Service to connect with Mobile and Scanner for scanning and sending beacon data to Uart.

After combining code, I can connect to device using Mobile. and Device also receives the beacon.

When when I connect with device it stops Scanner. I want to make connection to configure device and Scanner should also work at this time.

Thank You

Bivay   



Parents
  • Hello,

    You must start scanning again after the connection has been made. You probably need to increase the number of central connections that the device has, or else you will get an error when you try to start the scan when you are already connected. 

    Search for NRF_SDH_BLE_CENTRAL_LINK_COUNT and NRF_SDH_BLE_TOTAL_LINK_COUNT. They should both be set to 2.

    Best regards,

    Edvin

  • Thanks for response.

    I want to send beacon data using NUS to mobile. and its only possible if scanner and NUS works simultaneously.

    Please consider above statement to help me.

    Thank You

    Bivay

  • Sorry, I mixed the nus_c and nus. 

    Either way, you need to start scanning in addition to advertising. In that case, you must set NRF_SDH_BLE_CENTRAL_LINK_COUNT to 1, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT to 1 and NRF_SDH_BLE_TOTAL_LINK_COUNT to 2.

    Then you start scanning like it is done in the ble_central examples, and you start advertising like it is done in the ble_perpheral examples.

    If you want some further inspiration, you can check out the example found in:

    SDK\exapmles\ble_central_and_peripheral\experimental\ble_app_hrs_rscs_relay, which does both scanning and advertising.

    Best regards,

    Edvin

  • Dear,

    Thanks for support, From our help I get one step ahead. When I connect to NUS Device with scanner, Scanner works as expected, I can see data of beacon on logger even after connection. But There is another issue After connection when I transmit data from Mobile to Device, It doesn't receive data and scanner is also stopped for some time about 9 seconds.

    In mobile I get Two Errors:

    ERROR 133 (0x85): GATT ERROR

    ERROR 8 (0x8) : GATT CONN TIMEOUT

    After this message device again start scanning of beacon and advertise.

    If I didn't send data on NUS Bus then Scanner works but NUS get disconnect with below error after nearby 9 seconds.

    ERROR 8 (0x8) : GATT CONN TIMEOUT

    But when at event BLE_GAP_EVT_CONNECTED, if I stop scanning using sd_ble_gap_scan_stop(), NUS Bus works. and at event BLE_GAP_EVT_DISCONNECTED I start scanning again.

    Please Help me regarding this.

    Thank You

    Bivay

  • It looks like your nRF application is crashing. Have you tried monitoring the log from the nRF5840?

    If it says "Fatal error" somewhere, try to add DEBUG in your preprocessor definitions. (Let me know what IDE you are using if you are not sure how to do this).

    BR,

    Edvin

  • Dear Edvin,

    Thanks for help I will debugging in code. but there is no "fatal error". code is running as expected after above error. This is found from log of start print. If I provide you my code can you please look for issue in it.

    My Goal is a Android mobile is connected to My NRF52840 device. This device scans the beacon continuously and transmit beacon data to Android Mobile in NUS.

    My problem is when scanning runs can't use NUS. and when use NUS can't use scan for beacon. Both scan and NUS runs independent perfectly. My goal is to run both simultaneously.

    Please find attachement. 

    I am using Segger Studio 4.20 as IDE.

    SDK: nRF5_SDK_16.0.0_98a08e2

    Please copy code in following folder : nRF5_SDK_16.0.0_98a08e2\examples\ble_peripheral

    Thank You

    Bivay

    ble_app_uart - v1.zip

     
  • bivay said:
    My problem is when scanning runs can't use NUS. and when use NUS can't use scan for beacon.

     Can you explain why you can't use them? What happens if you try to use NUS while scanning? And what happens if you try to scan while you use NUS?

Reply Children
  • I already described my issue, but once again:

    I am using the attached code with sdk16.0.0, extract to nRF5_SDK_16.0.0_98a08e2\examples\ble_peripheral.

    When this code starts, I get beacon data on RTT Viewer, and get advertisement in Android NRF Connect Application. When I press connect button on NRF Connect Application, New tab is opned and shows connected, but in this situation I didn't get beacon data on RTT viewer by Scanner Module. 

    Then, after some time in NRF Connect Application, Device get disconnect with following error:

    ERROR 8 (0x8) : GATT CONN TIMEOUT

    And then in RTT viewer I can see beacon data again.

    I can confirm that NRF52840 is not reset or reboot or hangs during this process.


    But when at event BLE_GAP_EVT_CONNECTED, if I stop scanning using sd_ble_gap_scan_stop(), NUS Bus works perfectly (Can't see beacon data on RTT viewer). and at event BLE_GAP_EVT_DISCONNECTED (when I disconnect manually from NRF Connect Application), when start scanning again, it scan and shows beacon data on RTT viewer.

    My problem is when scanning runs can't use NUS. and when use NUS can't use scan for beacon. Both scan and NUS runs independent perfectly. My goal is to run both simultaneously.

    Thank You 

    Bivay

  • Hello,

    I tested your project now. I am struggling to recreate the issues that you describe.

    Can you please confirm that

    1: You run this on an nRF52840 DK from Nordic (or do you use a 3rd party DK?)

    2: That you use the S140 softdevice from SDK16.0.0, and

    3: That you are using the project found in the folder pca10056\s140\ses ?

    The reason I ask about the folder is that I had to add the path to the nrf_ble_scan.h before I could compile.

    I was able to see the advertisements in the RTT log, to see the device advertising itself, to connect to it using nRF Connect for Mobile, and to send and receive data using the NUS service while I could see the RTT print of advertisements coming in all the time.

    If you still experience the issues that you describe:

    Confirm 1,2 and 3 above,

    Maybe you changed some files outside the project folder? Try to unzip the project that you sent me in an unmodified version of the SDK (download from nordicsemi.com and unzip, so that you know that it is not modified).

    If that doesn't help, please try to capture a sniffer trace, and monitor the log output from the application. Does it say anything other than the advertising reports?

    You can use nRF Sniffer to capture a sniffer trace.

    Best regards,

    Edvin

  • Dear,

    Thanks for your support.

    I didn't changed anything in sdk. This is fresh SDK.

    About your queries:

    1) My module is 3rd party module : cdebyte e73-2g4m08s1c. I used external 32.768kHz external crystal on P0.0 and P0.1.

    2) Yes I used s140.

    3) My path of project is : nRF5_SDK_16.0.0_98a08e2\examples\ble_peripheral\ble_app_uart - v1\pca10056\s140\ses

    some of my question about your testing:

    1) Have you tried my code and get both NUS and Scanner Working together. means able to send beacon data on NUS bus to mobile (this is not implemented in my code yet), if not could you check, please.

    2) Have you sent data from Mobile and seen in RTT viewer using NUS and at this time scanner is also working means seen beacon data in RTT Viewer.

    I will try to unzip SDK again and try my code.

    Thank You

    Bivay

  • bivay said:
    Have you sent data from Mobile and seen in RTT viewer using NUS and at this time scanner is also working means seen beacon data in RTT Viewer.

    Hello,

    I didn't implement this to check, but I was able to see the data that I entered via UART on the mobile, and I was able to see the data that I sent from nRF Connect on mobile on the RTT window.

     

    bivay said:
    My module is 3rd party module : cdebyte e73-2g4m08s1c. I used external 32.768kHz external crystal on P0.0 and P0.1.

     Perhaps it is a different XTAL than the one we use on the DK. Does the 3rd party module mean that the XTAL came with the module, or did you add that yourself?

    Look up the datasheet on the LFXTAL (connected to P0.0 and P0.01). What is the accuracy of the XTAL? Make sure that the define, NRF_SDH_CLOCK_LF_ACCURACY, in sdk_config.h matches the accuracy of your LFXTAL.

    Best regards,

    Edvin

  • Thank You Edvin.

    You are right this is crystal issue, when I use internal RC clock then issue solved.

    Thank you so much for your kid support

    Bivay

Related