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

comparision of uart received data

hi,

i am using nrf51422 ble_app_uart(sdk 12.3.0) example

i am receiving a string  through app_uart_get() function, i want to compare it then i have  to send some predefined string using ble_nus_string_send() function. how can i do it?

  • Hi.

    Not quite sure what you mean by "compare it", you can use memcmp (compare two blocks of memory) or an if-sentence to compare it?

    If sentence explained here.
    memcmp explained here.

    The ble_nus_string_send() function and the Nordic UART Service API for SDK 12.3 can be found here.

    Hope this helps.

    - Andreas

  • Thanks for your reply, ya i am able to compare string using if statement.

    please check my code, here once i transmit a string  through terminal i am receiving the values(defined my me) continuously. But what i want is if i transmit data through terminal i should receive it only one time in my mobile app

    thank you.

    int main(void)
    {
        uint32_t err_code;
        bool erase_bonds;
    
        // Initialize.
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
        uart_init();
    
        buttons_leds_init(&erase_bonds);
        ble_stack_init();
        gap_params_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        printf("\r\nUART Start!\r\n");
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    	
        // Enter main loop.
        for (;;)
        {
    			power_manage();
    			 
    			if ((data_array[0] == 'u') && (data_array[1] == 'p'))
    					{
    						err_code = ble_nus_string_send(&m_nus, up, 3);
    						index = 0;
    								
    					}
    		 if((data_array[0] == 'd') && (data_array[1] == 'o')&&(data_array[2]=='w')==(data_array[3]=='n'))
              {
    						err_code = ble_nus_string_send(&m_nus, down, 3);
    						index = 0;
              }			
          
                
       }
    }

  • This is basic program design - nothing specifically to do with Nordic!

    Think about it: If nothing writes to the data_array[], then it will continue to contain the same data - so your strings will match each time round the main loop.

    If you want the string to be handled only once, then you will need some way to know that you have already handled it - won't you ... ?

Related