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

FreeRTOS + ble_app_uart_c +SPI(for external sensor) = instability

I used nRF52832 , SDK 15.0 ,S132,FreeRTOS 10(From "ble_app_hrs_freertos")。

My work needs to be realized three functions:

(1) From "ble_uart_c" method receive another BLE send data;

(2) Use the FreeRTOS resolved the multi-task;

(3) From SPI to receive the external sensor data ( 200Hz ,by interrupt).

First I transplanted the FreeRTOS from   "ble_app_hrs_freertos" sample, and used to  "ble_app_uart_c " sample , it worked well, it's ok.

Second  I added the external sensor interrupt and event-Handle, and it also work well;

Finally ,I put them together , the problem is , the "ble_uart_c"  will connects, disconnects, and reconnects frequently, the connected time is more than ten seconds.

I think maybe is the Priority problem,but I set the "#define configMAX_PRIORITIES    ( 5 )" , and set the "ble_uart_c"  4;  and set the "#define taskPRIO_RxData 3 "(receive the sensor data function task), and it's not work, I am very confused and worried.

Can you help me ,thanks very much ,I will be waiting!

// the INT of Sensor
static void vINTHandler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t actio)
{
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    G_Counter++;
    xTaskNotifyFromISR(xTaskHandle_RxData_MPU9255,     
                       G_Counter,               
                       eSetValueWithOverwrite,
                        &xHigherPriorityTaskWoken);
     
     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

//the task of Rx Sensor data
static void vTask_RxData_MPU9255(void *pvParameters)
{

    uint8_t error_temp = 0;
    while(1)
    {

        xTaskNotifyWait(0x00000000,     
                        0xFFFFFFFF,     
                        NULL,                 
                        portMAX_DELAY);       
        
        memcpy(G_Data+6,&G_MicroSecond,2);
        memcpy(G_Data+2,&G_WeekSecond,4);
        memcpy(G_Data+8,&G_Counter,4);   
    }
}

They both work very well separately, but when they work together they have problems, they seem to interfere with each other. 

Parents
  • And the "ble_app_uart_c" setting is like this:

    #define APP_BLE_CONN_CFG_TAG    1                                       /**< A tag that refers to the BLE stack configuration we set with @ref sd_ble_cfg_set. Default tag is @ref BLE_CONN_CFG_TAG_DEFAULT. */
    #define APP_BLE_OBSERVER_PRIO   3                                       /**< Application's BLE observer priority. You shoulnd't need to modify this value. */
    
    
    #define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN              /**< UUID type for the Nordic UART Service (vendor specific). */
    
    #define SCAN_INTERVAL           0x00A0                                  /**< Determines scan interval in units of 0.625 millisecond. */
    #define SCAN_WINDOW             0x0050                                  /**< Determines scan window in units of 0.625 millisecond. */
    #define SCAN_DURATION           0x0000                                  /**< Timout when scanning. 0x0000 disables timeout. */
    
    #define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS)         /**< Determines minimum connection interval in millisecond. */
    #define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS)         /**< Determines maximum connection interval in millisecond. */
    #define SLAVE_LATENCY           0                                       /**< Determines slave latency in counts of connection events. */
    #define SUPERVISION_TIMEOUT     MSEC_TO_UNITS(4000, UNIT_10_MS)         /**< Determines supervision time-out in units of 10 millisecond. */
    
    Maybe the time is not appropriate? 

Reply
  • And the "ble_app_uart_c" setting is like this:

    #define APP_BLE_CONN_CFG_TAG    1                                       /**< A tag that refers to the BLE stack configuration we set with @ref sd_ble_cfg_set. Default tag is @ref BLE_CONN_CFG_TAG_DEFAULT. */
    #define APP_BLE_OBSERVER_PRIO   3                                       /**< Application's BLE observer priority. You shoulnd't need to modify this value. */
    
    
    #define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN              /**< UUID type for the Nordic UART Service (vendor specific). */
    
    #define SCAN_INTERVAL           0x00A0                                  /**< Determines scan interval in units of 0.625 millisecond. */
    #define SCAN_WINDOW             0x0050                                  /**< Determines scan window in units of 0.625 millisecond. */
    #define SCAN_DURATION           0x0000                                  /**< Timout when scanning. 0x0000 disables timeout. */
    
    #define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS)         /**< Determines minimum connection interval in millisecond. */
    #define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS)         /**< Determines maximum connection interval in millisecond. */
    #define SLAVE_LATENCY           0                                       /**< Determines slave latency in counts of connection events. */
    #define SUPERVISION_TIMEOUT     MSEC_TO_UNITS(4000, UNIT_10_MS)         /**< Determines supervision time-out in units of 10 millisecond. */
    
    Maybe the time is not appropriate? 

Children
No Data
Related