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

nrf51822 event on_ble_write

hi nordic;

i need your help, i'm trying to code a control of gpio over the BLE i have an app on android with it i can establish connection and see the service and charactrestic but the problem that i have, is with event on_ble_write i want juste change the state of the pin 20 on my nrf51822 pca20006 just after receiving any kind of data but it didin't work .

to recap the idea of the code attached i have function returnei returnes a variable ii after sending some data from smartphone to nrf over ble this variable intially is at value 2 after sending the data its value will be at 0 and the pin 20 will be at low state but unfortunately this didn't work

any help from you will be appreciated

main.c

our_service.c

our_service.h

Parents
  • now i updated my ii in both cases but the 20 pin is still without any change

    static void on_ble_write(ble_os_t * p_our_service, ble_evt_t * p_ble_evt)
    {
        // Declare buffer variable to hold received data. The data can only be 32 bit long.
        uint32_t data_buffer;
        // Populate ble_gatts_value_t structure to hold received data and metadata.
        ble_gatts_value_t rx_data;
        rx_data.len = sizeof(uint32_t);
        rx_data.offset = 0;
        rx_data.p_value = (uint8_t*)&data_buffer;
        
        // Check if write event is performed on our characteristic or the CCCD
        if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles.value_handle)
        {
    				ii=0;
            // Get data
            sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles.value_handle, &rx_data);
            // Print handle and value 
            printf("Value received on handle %#06x: %#010x\r\n", p_ble_evt->evt.gatts_evt.params.write.handle, data_buffer);
    			  
        }
        else if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles.cccd_handle)
        {
            // Get data
    			ii=0;
            sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles.cccd_handle, &rx_data);
            // Print handle and value 
    			
            printf("Value received on handle %#06x: %#06x\r\n", p_ble_evt->evt.gatts_evt.params.write.handle, data_buffer);
            
    			if(data_buffer == 0x0001)
            {
                printf("Notification enabled\r\n");
    				//	ii=0;
            }
            else if(data_buffer == 0x0000)
            {
                printf("Notification disabled\r\n");
    				//	ii=1;
            }
        }
    }
    
Reply
  • now i updated my ii in both cases but the 20 pin is still without any change

    static void on_ble_write(ble_os_t * p_our_service, ble_evt_t * p_ble_evt)
    {
        // Declare buffer variable to hold received data. The data can only be 32 bit long.
        uint32_t data_buffer;
        // Populate ble_gatts_value_t structure to hold received data and metadata.
        ble_gatts_value_t rx_data;
        rx_data.len = sizeof(uint32_t);
        rx_data.offset = 0;
        rx_data.p_value = (uint8_t*)&data_buffer;
        
        // Check if write event is performed on our characteristic or the CCCD
        if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles.value_handle)
        {
    				ii=0;
            // Get data
            sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles.value_handle, &rx_data);
            // Print handle and value 
            printf("Value received on handle %#06x: %#010x\r\n", p_ble_evt->evt.gatts_evt.params.write.handle, data_buffer);
    			  
        }
        else if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles.cccd_handle)
        {
            // Get data
    			ii=0;
            sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles.cccd_handle, &rx_data);
            // Print handle and value 
    			
            printf("Value received on handle %#06x: %#06x\r\n", p_ble_evt->evt.gatts_evt.params.write.handle, data_buffer);
            
    			if(data_buffer == 0x0001)
            {
                printf("Notification enabled\r\n");
    				//	ii=0;
            }
            else if(data_buffer == 0x0000)
            {
                printf("Notification disabled\r\n");
    				//	ii=1;
            }
        }
    }
    
Children
No Data
Related