I now this are basics. And I did this allready a few times, but in this project it simply wont work. Maybe someone of you will find something, that is missing.
I`m working with the ble_app_template from SDK 8.1.
Hardware: nRF51DK Softdevice: 8.0 MCP v3.7.1
And this is my problem:
With the MCP I'm able to connect with my board. I'm also able to discover services. Now when I try to write a value(as example 0x01) to a characteristic, I will never get into the auf_write_handler(which is the handler for the characteristic.
This is the Log from the MCP:
UpdateAttributeValue(mode=0)
WriteRequest sent to handle 0x000B with value [1]
Updated handle 000B with value [1]
I will attach the main.c,motocontrol.c and motocontrol.h file:
Here the set up for the characteristic:
static void on_write(ble_moco_t * p_moco, ble_evt_t * p_ble_evt)
{
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if ((p_evt_write->handle == p_moco->ab_char_handles.value_handle) &&
(p_evt_write->len == 1) &&
(p_moco->ab_write_handler != NULL))
{
p_moco->ab_write_handler(p_moco, p_evt_write->data[0]);
}
if ((p_evt_write->handle == p_moco->auf_char_handles.value_handle) &&
(p_evt_write->len == 1) &&
(p_moco->auf_write_handler != NULL))
{
p_moco->auf_write_handler(p_moco, p_evt_write->data[0]);
}
}
void ble_moco_on_ble_evt(ble_moco_t * p_moco, ble_evt_t * p_ble_evt)
{
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_moco, p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_moco, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
on_write(p_moco, p_ble_evt);
break;
default:
// No implementation needed.
break;
}
}
static uint32_t auf_char_add(ble_moco_t * p_moco, const ble_moco_init_t * p_moco_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL; //Notification/Indication
char_md.p_sccd_md = NULL;
ble_uuid.type = p_moco->uuid_type;
ble_uuid.uuid = MOCO_UUID_AUF_CHAR;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t);
attr_char_value.p_value = NULL;
return sd_ble_gatts_characteristic_add(p_moco->service_handle,&char_md,&attr_char_value,&p_moco->auf_char_handles);
}
uint32_t ble_moco_init(ble_moco_t * p_moco, const ble_moco_init_t * p_moco_init)
{
uint32_t err_code;
ble_uuid_t ble_uuid;
p_moco->conn_handle = BLE_CONN_HANDLE_INVALID;
p_moco->auf_write_handler = p_moco_init->auf_write_handler;
p_moco->ab_write_handler = p_moco_init->ab_write_handler;
ble_uuid128_t base_uuid = MOCO_UUID_BASE;
err_code = sd_ble_uuid_vs_add(&base_uuid, &p_moco->uuid_type);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
ble_uuid.type = p_moco->uuid_type;
ble_uuid.uuid = MOCO_UUID_SERVICE;
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_moco->service_handle);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = auf_char_add(p_moco, p_moco_init);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = ab_char_add(p_moco, p_moco_init);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
return NRF_SUCCESS;
}
And this is the handler which I set up for the characterstic:
static void auf_write_handler(ble_moco_t *p_moco, uint8_t auf_state)
But I will never get into this handler.
Why not?