notification_problem.rarHi everyone
I would like to send a large number of bytes from nrf51822 to my central device. To be everything reliable and efficient I decided to use characteristic with notification. The test method is implemented in the following way:
uint32_t ble_mgs_history_send(uint16_t index)
{
uint32_t err_code;
if (m_mass.conn_handle != BLE_CONN_HANDLE_INVALID)
{
uint16_t hvx_len;
ble_gatts_hvx_params_t hvx_params;
if(m_mass.mass_counter == 0)
{
for(uint16_t i = 0; i < 250; i= i + 1)
{
m_mass.histroy_last[i] = i;
m_mass.histroy_last[i + 250] = 250 - i;
}
}
m_mass.history_counter = 500;
for(uint16_t j = 0; j < m_mass.history_counter; j = j + 20)
{
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = m_mass.history_char_handles.value_handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_len = 20;
hvx_params.p_len = &hvx_len;
hvx_params.p_data = &m_mass.histroy_last[j];
err_code = sd_ble_gatts_hvx(m_mass.conn_handle, &hvx_params);
**m_mass.notification_flag = 2;**
while(m_mass.notification_flag != 1)
{
power_manage();
}
m_mass.notification_flag = 0;
if (err_code != NRF_SUCCESS)
{
SEGGER_RTT_WriteString(0, "Error\n");
}
}
}
else
{
err_code = NRF_ERROR_INVALID_STATE;
}
return err_code;
}
The entire code works fine, the function sd_ble_gatts_hvx sends 20bytes and after that, I get event handler BLE_EVT_TX_COMPLETE where variable m_mass.notification_flag is set to 1. On the other hand, if I remove the power_manage() function then the program sticks in a while function. If I am honest I do not know why this happens, because the function ble_mgs_history_send is executed in the main function via the scheduler. I will be grateful for any kind of suggestions
Samo