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

How to sent a 200 bytes data packet via NUS every 20ms between nRF52832 and nRF52840

Hello, I'm making a system with NUS of nRF52832 and nRF52840 to sample data with SAADC. I started the system with "ble_app_uart__saadc_timer_driven__scan_mode_03" from Github "NordicPlayground". The link is below: nRF52-ADC-examples/README.md at master · NordicPlayground/nRF52-ADC-examples (github.com).

The source code is based on timer driven to sample the data and transmit via NUS(Nordic UART Service) in a nRF52832 board. The data is transmit to NRF52840 DK board which served as central board and sent to the computer via UART port. 

Now I need to realize a 1kHz sample rate with 4 channels and 12bit resolution. It is too frequency to send data every 1ms. So I save the data in an buffer and transfer the data every 10 samples. In the source code, the sample rate is define as below.

#define SAADC_SAMPLES_IN_BUFFER         4
#define SAADC_SAMPLE_RATE               5                                         /**< SAADC sample rate in ms. */    

I can decease the sample interval to 4 or 5 and the data can be transfer to computer with no problem. But when I decrease the sample interval to 1ms and increase the sample rate to 1kHz, the BLE connection has some problem and data cannot be sent to central board and computer. What cause the problem? I have adjusted the advertising time of the peripherals and scan time of the central, but it didn't work. I have posted some questions before and got some suggestion about that, the typical answer is based on https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/multilink_scheduling/central_connection_timing.html . I can partly understand that but I didn't know how to match the timing parameter between the website and the source code. Would you please help me solve that? Any help will be appreciated. 

  • On the central side, I used "nrf52-ble-app-uart-c-multilink-master" as example. It's also based on the "ble_app_multilink_central" project in "ble_central " folder. I didn't find any connection parameter in main.c but I get some in the sdk_config.h files which listed below. Does it match the peripheral firmware? Thanks.

    // <o> NRF_BLE_SCAN_SCAN_INTERVAL - Scanning interval. Determines the scan interval in units of 0.625 millisecond. 
    #ifndef NRF_BLE_SCAN_SCAN_INTERVAL
    #define NRF_BLE_SCAN_SCAN_INTERVAL 160               //160
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_DURATION - Duration of a scanning session in units of 10 ms. Range: 0x0001 - 0xFFFF (10 ms to 10.9225 ms). If set to 0x0000, the scanning continues until it is explicitly disabled. 
    #ifndef NRF_BLE_SCAN_SCAN_DURATION
    #define NRF_BLE_SCAN_SCAN_DURATION 0
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_WINDOW - Scanning window. Determines the scanning window in units of 0.625 millisecond. 
    #ifndef NRF_BLE_SCAN_SCAN_WINDOW
    #define NRF_BLE_SCAN_SCAN_WINDOW 80                     //80
    #endif
    
    // <o> NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL - Determines minimum connection interval in milliseconds. 
    #ifndef NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL
    #define NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL 7.5       //7.5
    #endif
    
    // <o> NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL - Determines maximum connection interval in milliseconds. 
    #ifndef NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL
    #define NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL 30      //30
    #endif

  • Since the "Windows size" and "interval" is a index number and the real time is about "1.25" proportional to the number, so I guess we should correct the MIN_CONN_INTERVAL and MAX_CONN_INTERVAL in the peripheral. Am I right? But when I decreased the parameters to 5 and 35 respectively, The peripheral will keep in fatal errors. How to correct that? Thanks.

  • If you build with DEBUG then you should get more information about the error from app_error_fault_handler() in app_error_weak.c

    Kenneth

Related